In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to define the data in Vue, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
In Vue, variables can be divided into two types according to whether or not two-way data binding is required:
One is to be hijacked by the data of Vue to respond the changes of data to view in real time.
As long as the msg that data can only change, the msg bound in template will respond in real time.
{{msg}} export default {data () {msg: ""}}
There is another way that does not need to be hijacked by Vue data:
Only valid in script, not used in template, no data hijacking is required
Name is only valid in the concatName function, so it can be defined as a local variable.
Age needs to be used in both getAge and concatName functions, but it is not appropriate to use it as a local variable, so its scope can be improved to facilitate its use in multiple places.
Const age = 'bar'export default {methods: {getAge () {return age}, concatName () {let name =' nordon' reutrn `name:$ {name}, age: ${age} `},}
Only used as rendering data in template, it will not be modified in subsequent operations after customization, and some performance will be wasted if this kind of data is hijacked by Vue.
{{item.name}} const arr = Object.freeze ([{name: 'nordon', age: 18}]) export default {data () {return {arr}
Using Object.freeze to freeze the data that does not need data hijacking, it will not be hijacked when recursively traversing the data in Vue, especially for a large number of table classes.
You can see from the Vue source code why there is no data hijacking after using Object.freeze to process the data.
Function defineReactive (obj, key) {/ / delete extraneous code only retains the judgment condition const property = Object.getOwnPropertyDescriptor (obj, key) if (property & & property.configurable = false) {return}} above is all the content of this article "how to define data 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.