Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does vue reset all properties of data

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "vue how to reset all the attributes of data", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how vue resets all the attributes of data" article.

Reset all properties of data 1. Get the original data attribute this.$options.data () 2. Get the current datathis.$data3. Copy to the current $data Object.assign (this.$data, this.$options.data ()); reset the data problem of the current page

In some cases, you need to reuse the data in data, but the data in data has been assigned by various forms, variables, and so on, so how do you reset the value of data?

Solution: Object.assign ()

JS correlation function

Function meaning Object.assign (target, … Sources) copies all enumerable attribute values from one or more source objects to the destination object

Correlation function in vue

The function means datathis.$options.data in the current state of this.$data () the data in the initial state of the component

Therefore, you can reset the data of the current page in the following ways:

Object.assign (this.$data, this.$options.data.call (this))

Or, reset one of the objects or properties in the data separately:

This.form = this.$options.data (). Form question two

When you reset the component data with this.$options.data (), the props or methods obtained with this in data () is undefined.

Reason

New Vue passes an object, which is recorded as options,Vue. The custom properties in options and the properties defined in the Vue constructor are merged into this in vm.options,vm.options.data () pointing to vm.options, while methodA and B are not directly hung under vm.options, so this.methodA and this.B are undefined.

The above is the content of this article on "how vue resets all the properties of data". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report