diff --git a/runtime/main/model/index.ts b/runtime/main/model/index.ts index ac5324e6..cc1ea5f8 100644 --- a/runtime/main/model/index.ts +++ b/runtime/main/model/index.ts @@ -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; } diff --git a/runtime/main/model/pageLife.ts b/runtime/main/model/pageLife.ts index f5db2b34..4deada95 100644 --- a/runtime/main/model/pageLife.ts +++ b/runtime/main/model/pageLife.ts @@ -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]; } }); } diff --git a/test/ut/model/index.ts b/test/ut/model/index.ts index d9beb95c..5195282c 100644 --- a/test/ut/model/index.ts +++ b/test/ut/model/index.ts @@ -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', () => {