我是vue初学者
我正在尝试使用 name 推送计算数据,该名称来自创建实例后出现的 vuex
如何将新的计算属性推送到 created() Hook 中的实例??
这是代码
computed: {
// 3 - i want to extract the object properties here computed
// that is easy bu using spread operator ...
// Problem : vue intialize computed before the created() hook
// so the spreed work befor passing the filling the object
...this.mapGettersObj
},
created(){
// 1- i can access only this line after creating the object
this.stocks = this.$store.state
let arr=[]
for (let stock in this.stocks){
arr.push(stock+'Getter')
}
// 2 - mapGetters returns an object
this.mapGettersObj=mapGetters(arr)
}
如果我可以在创建后创建新的计算值就可以解决问题
最佳答案
你可以在 beforeCreate 钩子(Hook)中这样做。
beforeCreate: function() {
this.$options.computed = {
demo2: function() {
return this.demo
}
}
}
关于vue.js - vue 计算 : add new computed value from created lifecycle hook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43782086/