Skip to content

Commit db61a6e

Browse files
committed
fix: material.component lose reactive because of destructuring
1 parent f812934 commit db61a6e

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

  • packages/plugins/materials/src/meta/component/src

packages/plugins/materials/src/meta/component/src/Main.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</template>
3636

3737
<script lang="ts">
38-
import { inject, onMounted, reactive, ref, watchEffect } from 'vue'
38+
import { inject, onMounted, reactive, ref, watch, watchEffect } from 'vue'
3939
import { Collapse, CollapseItem, Search } from '@opentiny/vue'
4040
import { SearchEmpty, CanvasDragItem } from '@opentiny/tiny-engine-common'
4141
import i18n from '@opentiny/tiny-engine-common/js/i18n'
@@ -57,7 +57,6 @@ export default {
5757
const { generateNode, materialState, getComponentsByGroup } = useMaterial()
5858
const gridTemplateColumns = ref(COMPONENT_PANEL_COLUMNS)
5959
const panelState = inject('panelState', {})
60-
const { components } = materialState
6160
const { locale } = i18n.global
6261
6362
const fetchComponents = (components, name) => {
@@ -91,10 +90,10 @@ export default {
9190
const initComponents = () => {
9291
const groupName = panelState.materialGroup
9392
if (groupName) {
94-
return getComponentsByGroup(components, groupName)
93+
return getComponentsByGroup(materialState.components, groupName)
9594
}
9695
97-
return components
96+
return materialState.components
9897
}
9998
10099
const state = reactive({
@@ -104,13 +103,23 @@ export default {
104103
})
105104
106105
watchEffect(() => {
107-
state.activeName = [...Array(components.length).keys()]
106+
state.activeName = [...Array(materialState.components.length).keys()]
108107
})
109108
110109
const change = (value) => {
111-
state.components = fetchComponents(components, value)
110+
state.components = fetchComponents(materialState.components, value)
112111
}
113112
113+
watch(
114+
() => materialState.components,
115+
(value) => {
116+
state.components = fetchComponents(value, state.searchValue)
117+
},
118+
{
119+
deep: true
120+
}
121+
)
122+
114123
const componentClick = (data) => {
115124
const { isShortcutPanel, emitEvent } = panelState
116125
const { addComponent } = useCanvas().canvasApi.value

0 commit comments

Comments
 (0)