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的屬性值進行修改


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM