Get the App
SLTechnology News&Howtos  ›  Development  › 

How does vue reset all properties of data

Shulou Source: shulou.com Published: 2022-05-31 21:21:47 09月21日 Update

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.

Tags: Attribute content function object meaning data article way state knowledge article component problem page original value reason variable can be passed multiple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL Apple macOS Shulou Information