我在全局对象中存储了一个变量,但是无论使用哪种方法,我似乎都无法访问它。这是代码:
// Component
let store = {
one: [{
text: 'storage',
value: '100'
}],
}
Vue.component('bs-panel', {
template: '#panel',
data: function() {
return {
count: store,
}
},
});
// Initialize Vue
new Vue({
el: '#app',
data: {
showPanel: true,
count: store.one,
},
beforeCreate: function() {
console.log('beforeCreate fired ' + this.count.one.value);
},
created: function() {
console.info('created fired ' + this.count.one.value);
},
beforeMount: function() {
console.log('beforeMount fired ' + this.count.one.value);
},
mounted: function() {
console.info('mounted fired: ' + this.count.one.value);
},
beforeUpdate: function() {
console.log('beforeUpdate fired ' + this.count.one.value);
},
updated: function() {
console.info('updated fired ' + this.count.one.value);
},
beforeDestroy: function() {
console.log('beforeDestroy fired ' + this.count.one.value);
},
destroyed: function() {
console.info('destroyed fired ' + this.count.one.value);
}
})
我一直收到控制台错误。
这是Jsfiddle:http://jsfiddle.net/syed263/z6joyhdL/2/
我在做什么错了?
答案 0 :(得分:1)
您需要将count : count.one[0].value
分配给两个组件,
并正确地进行控制,因为one
是一个数组。