Get the App
SLTechnology News&Howtos  ›  Development  › 

How does Vue empty objects?

Shulou Source: shulou.com Published: 2022-06-01 07:43:07 10月23日 Update

This article introduces the relevant knowledge of "how to clear objects in Vue". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Vue empty object JS empty object

Use the literal method to point to a new object:

Var obj = {name: 'Lee', age: 20}; obj = {}; var obj = {name:' Lee', age: 20}; for (var key in obj) {delete obj [key];} Vue empty the object

Use the literal amount of the object, not recommended.

Delete name: {{message.name}}, age: {{message.age}} var app = new Vue ({el:'# app', data: {message: {name: "Lee", age: 20}}, methods: {deleteInfo:function () {this.message = {};})

Use Vue.delete:

Delete name: {{message.name}}, age: {{message.age}} var app = new Vue ({el:'# app', data: {message: {name: "Lee", age: 20}}) Methods: {deleteInfo:function () {for (let key of Object.keys (this.message)) {Vue.delete (this.message,key) }) an object clears the vule value and retains the key

It is to copy the properties of one object to another.

In vue

This.$data gets the data in the current state

This.$options.data () gets the data in the initial state of the component

So, you can copy the data of the initial state to the data of the current state

To achieve the reset effect:

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

Of course, if you only want to reset an object or property in data: (usually used for form emptying data)

This.form = this.$options.data () .form

An object clears the vule value and retains the key

Object.keys (form) .forEach ((key) = > (form [key] =')) this is the end of the introduction of "how Vue cleans up objects". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Object status content name literal attribute age more knowledge practicality achievement and then dilemma reality that is situation point effect data article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei OPPO Reno Shulou Tech Info Xiaomi