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的属性值进行修改
不忘初心,不负梦想