vue 的计算属性
-
计算属性可以对数据进行简单的计算,再显示出来,对于methods来说,计算属性是有缓存的,如果数据不变,它会直接将缓存的数据显示出来
-
计算属性一般是没有set方法的,仅有get,只读属性
data:{ message:'hello', fistName: 'FirstName', lastName: 'LastName' }, computed : { //计算属性一般不会设置set方法,只读属性 // fullName : { // get : function (){ // return this.fistName + ' ' + this.lastName // }, // set : function (newValue){ // // console.log('+++++++') // const names = newValue.split(' '); //以空格的形式分割,将每一部分保存在 // names数组中 // this.fistName = names[0]; // this.lastName = names[1]; // } // } //一般简写为此形式 fullName : function (){ return this.fistName + ' ' + this.lastName } }