📜  重置反应状态 vue 3 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:57.283000             🧑  作者: Mango

代码示例1
// this not working for me if i have nasted array of object in intialState not sure way  
setup() {
    const initialState = {
      name: "",
      lastName: "",
      email: ""
    };

    const form = reactive({ ...initialState });

    function resetForm() {
      Object.assign(form, initialState);
    }

    function setForm() {
      Object.assign(form, {
        name: "John",
        lastName: "Doe",
        email: "john@doe.com"
      });
    }

    return { form, setForm, resetForm };
  }