vue当中计算属性重新计算依赖关系

时间:2019-11-06
本文章向大家介绍vue当中计算属性重新计算依赖关系,主要包括vue当中计算属性重新计算依赖关系使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

背景:学习vue的计算属性时,思考若计算属性fullName的返回值只由属性firstName和secondName决定

1:只修改 firstName和secondName 则必然导致 fullName 重新计算

2:若计算属性方法体内涉及到其他的属性的操作,那么该属性的变动是否会影响计算属性的重新计算呢

答案:会重新计算

export default {
    name: "Computed",
    data() {
        return {
            firstName: "pan",
            secondName: "rui",
            threeName: "hello",
        }
    },
    computed: {
        fullName: function () {
            console.log("是否重新计算")
            let string = this.threeName + "love"
            return this.firstName + " " + this.secondName
        }
    },
    methods: {
        changeFirstName: function () {
            this.threeName = "zhu"
        }
    },
}

3:测试计算属性时,经常会提示no-side-effects-in-computed-properties ,前往不要再计算属性当中,对data的属性值进行修改

原文地址:https://www.cnblogs.com/panrui1994/p/11804552.html