简体   繁体   English

vue.js 反应性和数据与 mixin

[英]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.我正在尝试根据某些条件设置一个标志,该标志可以是布尔值truefalse

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM