返回博客

Vue Data Resetting Techniques

This article explores different methods for resetting data in Vue.js applications, including resetting the entire data object or specific properties using `this.$data` and `this.$options.data()`. Learn how to efficiently restore your component's data to its initial state.

Mt.r
|

直接上代码

this.$data 获取当前状态下的 data this.$options.data() 获取该组件初始状态下的 data

所以,下面就可以将初始状态的 data 复制到当前状态的 data,实现重置效果: Object.assign(this.$data, this.$options.data())

当然,如果你只想重置 data 中的某一个对象或者属性: this.form = this.$options.data().form

转载

原文链接:https://blog.csdn.net/weixin_42054155/article/details/99889910