Vue 3.0 中如何重置 reactive 定义的数据,恢复为初始值? - 知乎
1、直接挨个重置数据(不适用对象中有多个属性,比较繁琐)
import { reactive } from 'vue'
const state = reactive({
count: 0,
name: 'John'
})
// 重置数据:
state.count = 0
state.name = 'John'
2、使用Object.assign()
import { reactive, ref } from "vue";
//保存初始化数据
const initInputData = {
datasourceName: "",
driverClassName: "",
url: "",
userName: "",
password: "",
startYear: "",
endYear: "",
status: true,
action: "submit",
id: "",
ip:'',
port:''
}
const inputData = reactive({...initInputData});
//重置函数
const resetInputData = () => {
Object.assign(inputData,initInputData)
}