In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "what are the computing attributes in Vue", the content is simple and clear, and I hope it can help you solve your doubts. Here, let me lead you to study and learn about "what are the computing attributes in Vue".
1. What is a computational attribute: in vernacular, the calculated result is saved in the attribute and can be thought of as a cache.
Title
CurrentTime1: {{currentTime1 ()}}
CurrentTime2: {{currentTime2}}
Var vm = new Vue ({el: "# app", data: {message: "hello vue!"}, methods: {currentTime1: function () {/ / returns the current timestamp return Date.now () }}, computed: {/ * Note: here are the calculation properties: and the methods and computed method names cannot be the same. After the duplicate name, only the methods method * / currentTime2: function () {this.message; / / returns the current timestamp return Date.now ();})
Running result:
Maybe it doesn't seem to make any difference at first glance.
But let's think about it carefully, one is the method, the other is the attribute.
As follows:
CurrentTime1: {{currentTime1 ()}}
CurrentTime2: {{currentTime2}}
Important: the attribute is stored in value, and it will not be changed until a new value comes in, otherwise it will be like caching. Let's take a look at this:
Explain:
1. In 1 and 2, we can see that one is the method and the other is the property, and it is certainly not possible for the property to be called by the method.
two。 In 1 and 3, we can see that the value of the method call changes all the time, but the value of the property call does not change, just as it is a caching mechanism.
3. In 3, 4, 5, we can see that once we change the value in the function, it is equivalent to changing the value in the cache, then it will refresh the value.
The above is all the content of the article "what are the Computational attributes in Vue?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.