Vue中computed计算属性

话不多说,使用方法直接上代码
//在模板中调用computedTest这个函数,切记不要在函数后添加()

export export{
 created(){

}

computed: { //计算属性 computedTest() { //计算属性中的一个函数,随便用,记得是return,return的数据就是页面上显示的数据,如果data中的数据发生变化,那么computed引用的数据也会发生变化 return ( //返回值 "computed在使用的过程中不在函数后添加()直接使用,只要data中的数据发生改变,那么computed的数据也会发生改变" + this.message2 + "this.$store.state.count的值为" + this.$store.state.count //这个 this.$store.state.count是我在Vuex里模拟的数据 ); }, }, }

【Vue中computed计算属性】 Vue中computed计算属性
文章图片

小结: 使用conputed可以极大程度上减少template中的文本描述,页面简洁,方便修改,需要敲代码的主动调用,调取缓存

    推荐阅读