Skip to content

Commit 9ff4f1f

Browse files
committed
商城装修:修复同一类型的组件切换时,右侧属性面板不更新的问题
1 parent a7512ba commit 9ff4f1f

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/components/DiyEditor/components/ComponentLibrary.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ watch(
8282
8383
// 克隆组件
8484
const handleCloneComponent = (component: DiyComponent<any>) => {
85-
return cloneDeep(component)
85+
const instance = cloneDeep(component)
86+
instance.uid = new Date().getTime()
87+
return instance
8688
}
8789
</script>
8890

src/components/DiyEditor/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
view-class="p-[var(--el-card-padding)] p-b-[calc(var(--el-card-padding)+var(--el-card-padding))] property"
112112
>
113113
<component
114+
:key="selectedComponent?.uid || selectedComponent?.id"
114115
:is="selectedComponent?.id + 'Property'"
115116
v-model="selectedComponent.property"
116117
/>
@@ -296,6 +297,7 @@ const handleMoveComponent = (index: number, direction: number) => {
296297
/** 复制组件 */
297298
const handleCopyComponent = (index: number) => {
298299
const component = cloneDeep(pageComponents.value[index])
300+
component.uid = new Date().getTime()
299301
pageComponents.value.splice(index + 1, 0, component)
300302
}
301303
/**

src/components/DiyEditor/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { TabBarProperty } from '@/components/DiyEditor/components/mobile/TabBar/
55

66
// 页面装修组件
77
export interface DiyComponent<T> {
8+
// 用于区分同一种组件的不同实例
9+
uid: number
810
// 组件唯一标识
911
id: string
1012
// 组件名称

0 commit comments

Comments
 (0)