-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] vue中怎么重置data? #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
只有问题没有答案吗 |
@Mary5haw 目前还没有人回答,你来回答下呗 |
使用Object.assign(),vm.$data可以获取当前状态下的data,vm.$options.data可以获取到组件初始化状态下的data,具体可以看vm.$options。 |
Object.assign(this.$data, this.$options.data()) |
Object.assign()方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象 |
初始状态下设置data数据的默认值,重置时直接bject.assign(this.$data, this.$options.data()) 说明: |
浅拷贝会影响到初始化的data吗? |
想问一句,这个使用场景在哪里?真的没碰见过需要重置的情况 |
比如,有一个表单,表单提交成功后,希望组件恢复到初始状态,重置data数据。 |
@censek 重置的意思 是使数据恢复成操作之前吗 不是置空是吗? |
1.使用Object.assign,可以重新绑定data的响应式。 |
我们可以通过this.$data获取当前状态下的data,通过this.$options.data()获取该组件初始状态下的data。 |
为啥不写个方法 this.data.form = {}? 说实话没太懂重置data的意义 ,能请教一下吗 |
可以设置表单的默认值。 |
使用 Object.assign(this.$data,this.$options.data.call(this)) 这样写才有用 |
|
Object.assign(this.$data, this.$options.data()) |
浅拷贝 |
这是我工作中用到的 this.formList = this.$options.data.call(this).formList |
懒加载 |
在加个this.$set()齐了 |
没用过,用作记录 Object.assign(this.$data, this.$options.data())方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象 |
我就是这样重置表单的数据的 |
聪明 |
mark 学到了 |
this.$options.data(),返回的就是data的初始值。 |
重新执行组件的 data 函数,这个函数可以在vm.$options中找到 |
[vue] vue中怎么重置data?
The text was updated successfully, but these errors were encountered: