[英]vue.js reactivity and data with mixin
我正在嘗試根據某些條件設置一個標志,該標志可以是布爾值true
或false
。
// main.js
new Vue({
el: `#app`,
render: h => h(App,{
props:{
todoID: this.dataset.id
}
})
})
我的應用程序腳本
export default {
name: 'App',
props: {
todoID: String,
},
data() {
return {
isDone: false // here is the initial flag
}
},
...
我創建了一個 mixin 方法
import Vue from "vue";
Vue.mixin({
methods: {
isCompleted() {
if (myconditions){
this.isDone = true; // I want to change the flag to true
}
},
},
});
在我的模板中,如果我執行{{isDone}}
我總是得到錯誤,我怎樣才能將其更改為反應性以便可以根據條件進行更改?
我猜當您調用isCompleted
函數時, myconditions
是未定義的。 所以最好傳遞true
。
isCompleted(myconditions) {
if (myconditions){
this.isDone = true; // I want to change the flag to true
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.