From 1be4f0fd7025367cd7ddc7010203d3a05d474646 Mon Sep 17 00:00:00 2001 From: qiang Date: Mon, 18 Jan 2021 16:01:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(App):=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=83=85=E5=86=B5=E4=B8=8B=20v-for=20=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=88=97=E8=A1=A8=E4=BA=8B=E4=BB=B6=E9=94=99=E4=B9=B1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20question/112100?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/framework/plugins/vdom-sync.js | 20 +++++++++++++++++-- .../view/framework/plugins/vdom-sync.js | 15 ++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) 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 2b9074f0f3..3c85f82f9e 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 2933b7d9a2..b426768e7d 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 } -} +} -- GitLab