In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
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!
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.