Get the App
SLTechnology News&Howtos  ›  Development  › 

How does vue assign null values to all key in an object

Shulou Source: shulou.com Published: 2022-06-01 00:22:36 09月21日 Update

This article mainly introduces "how vue assigns all the key in the object to null values". In the daily operation, I believe that many people have doubts about how vue assigns all the key in the object to null values. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how vue assigns all the key in the object to null values". Next, please follow the editor to study!

Assign all key in the object to null values

The use of Object.assign, of course, you can also use for to traverse and then one by one to assign an empty string, recommended to use (Object.assign)

Let's take a look at the basic usage of Object.assign.

The Object.assign method is used for merging objects. The first parameter (target object) can have the second and third parameters, both of which are source objects. All enumerable properties of the source object (source) are copied to the target object (target).

Const target = {target, source1, source2); const target = {target, source1, source2); console.log (target) / / {aVl1, bR2, cV3}

Note: the first parameter of the Object.assign method is the target object, and the following parameters are all source objects.

To get back to the point, sometimes the requirement encountered is that there are multiple input boxes, and each input box is v-modei bound with a corresponding value. When you click the reset button, you need to clear all the values in the input. In this case, you can use the Object.assign method. See the code for how to implement it.

Html code

Reset (empty input box)

Js code

Const values = {value1:'', value2:'', value3:'',} data () {return {valueData:Object.assign ({}, values)}}, methods: {/ / at this time, if you randomly enter a value in the input box, click the reset button, and you only need to re-copy it to valueData to clear the value in input. ToReset () {this.valueData = Object.assign ({}, values)}} vue null error problem

As shown in the above figure, the prompt percent is empty, and the web effect is as follows

If you don't want to bother in the self-test phase, just add data to the database or assign initial values to the initialization method. The easiest thing to do is to judge in vue template.

The code is as follows:

At this point, the study on "how vue assigns all the key in the object to null values" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Objects methods code parameters learning goals inputs buttons data more questions help practicality simplicity back to business and then three above multiple properties Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Docker Huawei MariaDB Redmi