$options
是一个记录当前Vue
组件的初始化属性选项。通常开发中,我们想把data
里的某个值重置为初始化时候的值,可以像下面这么写
this.value = this.$options.data().value;
在实际开发中,我们会遇到复杂的表单弹窗,例如新建弹窗,保存成功后一般会跳转到列表页,再次打开时需要清空表单数据及一些设置数据可以清空data。代码如下:
Object.assign(this.$data, this.$options.data.call(this));
但是涉及有表单校验的时候,再次打开页面,会走校验,此时需要处理下表单相关的
this.$refs.ruleFormRef.resetFields();
针对在data中定义的rules,目前还没有找到解决方法,我一般把rules写在dom中
这里小讲一下 Object.assign:
1 如果只有一个参数,Object.assign会直接返回该参数
const target = { a: 1, b: 2 };
const currentTarget = Object.assign(target);
console.log(currentTarget);
//{a: 1, b: 2}
如果该参数不是对象会转为对象,然后return;(undefined || null出现在target(源对象)位置无法转换为对象会报错)
const currentTarget = Object.assign(10);
console.log(currentTarget);
//Number {10}
其他类型的值(即数值,字符串和布尔值)不在首参数,也不会报错。但是,除了字符串会以数组形式,拷贝入目标对象,其他值都不会产生效果。
const source1 = "aaa";
const source2 = false;
const source3 = 666;
const currentTarget = Object.assign({}, source1, source2, source3);
console.log(currentTarget);
//{0: "a", 1: "a", 2: "a"}