Signed-off-by: lixingchi1 <lixingchi1@huawei.com>
This commit is contained in:
lixingchi1
2021-10-25 14:50:25 +08:00
parent 99268b30ec
commit 729ce6af5a
3 changed files with 11 additions and 11 deletions
+6 -6
View File
@@ -145,7 +145,7 @@ export default class Vm {
`'_innerInit' lifecycle in Vm(${this._type}) and mergedData = ${JSON.stringify(mergedData)}.`
);
this.$emit('hook:_innerInit');
this._data = (this.data !== undefined ? this.data : typeof data === 'function' ? data.apply(this) : data) || {};
this._data = (typeof data === 'function' ? data.apply(this) : data) || {};
this._shareData = (typeof shareData === 'function' ? shareData.apply(this) : shareData) || {};
this._descriptor = options._descriptor;
if (global.aceapp && global.aceapp.i18n && global.aceapp.i18n.extend) {
@@ -449,9 +449,9 @@ export default class Vm {
return;
}
if (key.indexOf('.') !== -1) {
_proxySet(this.data, key, value);
_proxySet(this._data, key, value);
}
set(this.data, key, value);
set(this._data, key, value);
}
/**
@@ -463,7 +463,7 @@ export default class Vm {
Log.warn(`Invalid parameter type: The type of 'key' should be string, not ${typeof key}.`);
return;
}
del(this.data, key);
del(this._data, key);
}
/**
@@ -659,11 +659,11 @@ export default class Vm {
* Data of this Vm.
* @type {*}
*/
public get data() {
public get __data() {
return this._data;
}
public set data(newData: any) {
public set __data(newData: any) {
this._data = newData;
}
+3 -3
View File
@@ -223,7 +223,7 @@ export function bindPageLifeCycle(vm: Vm, element: Element): void {
return vm.$emitDirect(`hook:${type}`, saveData);
}
function handleNewRequest(data: any) {
Object.assign(vm.data, data);
Object.assign(vm.__data, data);
return vm.$emitDirect(`hook:${type}`);
}
});
@@ -269,8 +269,8 @@ export function watch(vm: Vm, data: string, callback: ((...args: any) => any) |
*/
export function initPropsToData(vm: Vm): void {
vm.props.forEach(prop => {
if (vm.data) {
vm.data[prop] = vm[prop];
if (vm.__data) {
vm.__data[prop] = vm[prop];
}
});
}
+2 -2
View File
@@ -203,9 +203,9 @@ describe('api of communication between vm and data methods', () => {
doc.destroy();
const detail = { aaa: 1 };
vm.$set('test.aaa', detail);
expect(typeof vm.data['test.aaa']).eql('object');
expect(typeof vm.__data['test.aaa']).eql('object');
vm.$delete('test.aaa');
expect(typeof vm.data['test.aaa']).eql('undefined');
expect(typeof vm.__data['test.aaa']).eql('undefined');
});
it('$watch', () => {