diff --git a/src/platforms/app-plus/service/framework/plugins/vdom-sync.js b/src/platforms/app-plus/service/framework/plugins/vdom-sync.js index 2b9074f0f3268930c8f00fb3ca165722d04b8c94..3c85f82f9e161309472a0c1687cfbe72628c5175 100644 --- a/src/platforms/app-plus/service/framework/plugins/vdom-sync.js +++ b/src/platforms/app-plus/service/framework/plugins/vdom-sync.js @@ -13,9 +13,14 @@ import { PAGE_CREATE, PAGE_CREATED, MOUNTED_DATA, - UPDATED_DATA + UPDATED_DATA, + VD_SYNC_VERSION } from '../../../constants' +import { + generateId +} from '../../../helpers/util' + import { removeVdSync, registerVdSync @@ -113,7 +118,18 @@ export class VDomSync { } addVm (vm) { - this.vms[vm._$id] = vm + const id = vm._$id + const oldVm = this.vms[id] + if (oldVm) { + const newId = generateId(oldVm, oldVm.$parent, VD_SYNC_VERSION) + oldVm._$id = newId + this.vms[newId] = oldVm + this.elements.forEach(element => { + const cid = element.cid + element.cid = cid === id ? newId : cid + }) + } + this.vms[id] = vm } removeVm (vm) { diff --git a/src/platforms/app-plus/view/framework/plugins/vdom-sync.js b/src/platforms/app-plus/view/framework/plugins/vdom-sync.js index 2933b7d9a2c89d3ed0a91d29157bb93b4b69c2fe..b426768e7d0f35c4af13d25e278e4ca55bdeb920 100644 --- a/src/platforms/app-plus/view/framework/plugins/vdom-sync.js +++ b/src/platforms/app-plus/view/framework/plugins/vdom-sync.js @@ -35,6 +35,17 @@ export class VDomSync { this.updateBatchVData.push([cid, data]) } + addVm (vm) { + const id = vm._$id + const oldVm = this.vms[id] + if (oldVm) { + const newId = generateId(oldVm, findParent(oldVm), this.version) + oldVm._$id = newId + this.vms[newId] = oldVm + } + this.vms[id] = vm + } + initVm (vm) { vm._$id = generateId(vm, findParent(vm), this.version) let vData = this.addBatchVData[vm._$id] @@ -50,7 +61,7 @@ export class VDomSync { const [data, options] = vData Object.assign(vm.$options, options) vm.$r = data || Object.create(null) - this.vms[vm._$id] = vm + this.addVm(vm) } sendUIEvent (cid, nid, event) { @@ -89,4 +100,4 @@ export class VDomSync { }) this.updateBatchVData.length = 0 } -} +}