如果您有多个组件副本,如何单独触发对它们的更改?

时间:2017-04-18 23:29:01

标签: vue.js vuejs2

我试图使用计算属性来触发组件中的bool。我有这个组件的多个副本,但是如果每个组件都满足正确的要求,则需要单独触发它们。当bool设置为true时,它会影响所有副本。有没有一种标准的方法来处理这个问题?

1 个答案:

答案 0 :(得分:0)

我通过创建一个类对象作为计算属性来解决了这个问题。默认情况下,它将该类标记为已禁用。然后我使用if语句验证附加到每个组件的名称,如果为true,则该标志将针对该类的特定实例翻转为true。然后最后检查确认如果该标志设置为true然后激活该类。我确定有更有效的方法,如果你有一个请分享。

if(this.name === "Keywords" && this.view === "getViewCreateKeywords") {
        this.isActive = true;
    }

    if(this.name === "Listing" && this.view === "getViewCreateListing") {
        this.isActive = true;
    }

    if(this.name === "Backend" && this.view === "getViewCreateSummary") {
        this.isActive = true;
    }

    if(this.isActive) {
        return {
            disabled: this.isDisabled = false
        }
    }

    return {
        disabled: this.isDisabled = true
    }