Javascript 从字符串调用导入的对象
我有这个Vue插件Javascript 从字符串调用导入的对象,javascript,vue.js,Javascript,Vue.js,我有这个Vue插件 import Movement from './Movement' const PolicyCanPlugin = { install(Vue, {store}) { Vue.prototype.$policyCan = (model, method) => { // how can I call Movement.update_user() using the model(Movement) and method(up
import Movement from './Movement'
const PolicyCanPlugin = {
install(Vue, {store}) {
Vue.prototype.$policyCan = (model, method) => {
// how can I call Movement.update_user() using the model(Movement) and method(update_user) variables
}
}
}
我想从已经导入(移动)的动态模型调用dynamic方法
我想调用
这个。$policyCan('Movement','update_user')
并触发移动。update_user()
model[method]()将转换为model['update_user'])。这有帮助吗?为什么不使用vuex?@ssBarBee调用Movement['update_user']()
有效,但变量model[method]()
@HenriqueVanKlaveren我已经在使用vuex了,但我所有的突变和状态都在存储文件中,我可以编写另一个方法而不使用我的store.js
文件中的所有方法吗?从“/Movement”导入移动导出默认值({store})=>{const PolicyCanPlugin={store//are accessible here},这样你就可以使用你的store.state、store.getters..}