众所周知在vue2中,vue会把你传入的option会挂载到原型的$options上,并且data里面基本是函数返回的形式,所以我们可以用

this.xxx = this.$options.data().xxx

轻松重置data

但是在vue3中,我们写的代码基本都在setup中,定义的ref或者reactive,也可以用类似vue2的思路去解决这个问题

// 首先我们定义一个data
const wumao = ()=> {
  age:18,
  name:"wumao"
}
const refWumao = ref(wumao())
// 重置他
Object.assign(refWumao.value,wumao())
Last modification:October 9, 2021
If you think my article is useful to you, please feel free to appreciate