Home > Web Front-end > JS Tutorial > How to turn off the caching function of Vue calculated properties

How to turn off the caching function of Vue calculated properties

php中世界最好的语言
Release: 2018-04-12 13:53:10
Original
1408 people have browsed it

This time I will show you how to turn off the caching function of Vue's calculated property, and what are the precautionsfor turning off the Vue calculated property caching function. , the following is a practical case, let’s take a look.

Friends who use Vue will know the calculated properties of vue. This is explained in this way. When certain dependency values ​​change, its own value will also change, and the DOM related to it will also change. Usually, there are two methods in this calculated attribute: get and set can be used.

Here I will only analyze how to turn off the cache of calculated attributes and obtain the latest data, as shown in the following example:

HTML code

<p id="mess">
    <p>{{exapm}}</p>
  </p>
Copy after login

JS code:

 var vue2 = new Vue({
    el:"#mess",
    data:{
      sendmess:" i dhsjknkjvnkrenvr"
    },
  computed:{
    exapm:{
      cache:false,
      get:function(){
        return Date.now()+this.sendmess
      }
    }
    }
  });
Copy after login

We need to set cache to false, so that the cache is cleared and our time is the current time every time.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

AjaxUpLoad.js for file upload

How to use Vue’s carousel component

The above is the detailed content of How to turn off the caching function of Vue calculated properties. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template