[英]vue.js reactivity and data with mixin
I am trying to set a flag that can be a boolean value true
or false
based on certain conditions.我正在尝试根据某些条件设置一个标志,该标志可以是布尔值
true
或false
。
// main.js
new Vue({
el: `#app`,
render: h => h(App,{
props:{
todoID: this.dataset.id
}
})
})
my App script我的应用程序脚本
export default {
name: 'App',
props: {
todoID: String,
},
data() {
return {
isDone: false // here is the initial flag
}
},
...
I created a mixin method我创建了一个 mixin 方法
import Vue from "vue";
Vue.mixin({
methods: {
isCompleted() {
if (myconditions){
this.isDone = true; // I want to change the flag to true
}
},
},
});
in my template if I do {{isDone}}
I always get false, how can I change this to be reactive so it can be changed based on the conditions?在我的模板中,如果我执行
{{isDone}}
我总是得到错误,我怎样才能将其更改为反应性以便可以根据条件进行更改?
I guess myconditions
is undefine when you call isCompleted
funtion.我猜当您调用
isCompleted
函数时, myconditions
是未定义的。 So better to pass true
to it.所以最好传递
true
。
isCompleted(myconditions) {
if (myconditions){
this.isDone = true; // I want to change the flag to true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.