Vue计算属性的缓存


<h2>{{aa()}}</h2> <h2>{{aa()}}</h2> <h2>{{aa()}}</h2> <h2> {{ name }}</h2> <h2> {{ name }}</h2> <h2> {{ name }}</h2>

 


        methods: { aa() { console.log(
1111111111); return this.firstname + ' ' + this.lastname } }, computed: { name() { console.log(2222222); return this.firstname + ' ' + this.lastname } }
1111111111
1111111111
1111111111
2222222

最后输出的logmethods里面的aa()属性每次都调用,但computed只调用了一次

posted @ 2021-09-06 17:14  何歡  阅读(33)  评论(0)    收藏  举报