簡體   English   中英

vue.js 反應性和數據與 mixin

[英]vue.js reactivity and data with mixin

我正在嘗試根據某些條件設置一個標志,該標志可以是布爾值truefalse

// 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM