【发布时间】:2016-07-11 05:32:15
【问题描述】:
我有这样的代码:
Vue.component("sample", {
inherit: true,
template: "#sample",
props: {
active : "active",
...
},
methods: {
forceChangeActive: function(){
var activeItem = this.$parent._data.active;
var modalSetup = this.$parent._data.showModal;
console.log("1.before function", this.$parent._data);
this.$parent.$options.methods.baseAction(activeItem, modalSetup);
console.log("2.before function", this.$parent._data);
});
}
});
new Vue({
el: "#app",
data: {
active: 0,
showModal: false,
...
},
methods: {
baseAction: function(activeItem, modalSetup){
console.log("3.modal", modalSetup, "activeItem": activeItem);
modalSetup = true;
activeItem = 2;
console.log("4.modal", modalSetup, "activeItem": activeItem);
}
}
});
在新的 Vue 中有 active 和 showModal 数据变量。现在,如果我使用 this.active 或 this.showModal,我对两者都没有定义。 控制台输出为:
- 函数对象之前 { active=0, showModal=false }
- 模态错误,activeItem 0
- 模态真,activeItem 2
- 函数对象之前 { active=0, showModal=false }
如何在新的 Vue 或组件中更改变量的值?
【问题讨论】:
标签: vue.js