Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

vuejs中计算属性

就是关于vuejs的官方文档中,计算属性中说道 Date.now() 不是响应式依赖
图片描述

那这个函数的意思是在{{ now }}中不会改变吗?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

computed只会得到一次,就是首次调用的那次

以下代码也是,都被缓存起来了


let vm = new Vue({
    data() {
        return {
            nowCopy: 
        };
    },
    computed: {
      now: {
        get() {
          return Date.now();
        },
        
      }
    }
}
console.log(vm.now);

setTimeout(() => {
    console.log(vm.now);
}, 2000);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...