Skip to content

Commit e964e47

Browse files
committed
feat:【商城】店铺装修-搜索栏:新增热词,出现 object object 的情况
1 parent 415baa0 commit e964e47

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/components/DiyEditor/components/mobile/SearchBar/property.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- 表单 -->
44
<el-form label-width="80px" :model="formData" class="m-t-8px">
55
<el-card header="搜索热词" class="property-group" shadow="never">
6-
<Draggable v-model="formData.hotKeywords" :empty-item="''">
6+
<Draggable v-model="formData.hotKeywords" :empty-item="''" :min="0">
77
<template #default="{ index }">
88
<el-input v-model="formData.hotKeywords[index]" placeholder="请输入热词" />
99
</template>
@@ -61,13 +61,27 @@
6161
<script setup lang="ts">
6262
import { useVModel } from '@vueuse/core'
6363
import { SearchProperty } from '@/components/DiyEditor/components/mobile/SearchBar/config'
64+
import { isString } from '@/utils/is'
6465
6566
/** 搜索框属性面板 */
6667
defineOptions({ name: 'SearchProperty' })
6768
6869
const props = defineProps<{ modelValue: SearchProperty }>()
6970
const emit = defineEmits(['update:modelValue'])
7071
const formData = useVModel(props, 'modelValue', emit)
72+
73+
// 监听热词数组变化
74+
watch(
75+
() => formData.value.hotKeywords,
76+
(newVal) => {
77+
// 找到非字符串项的索引
78+
const nonStringIndex = newVal.findIndex((item) => !isString(item))
79+
if (nonStringIndex !== -1) {
80+
formData.value.hotKeywords[nonStringIndex] = ''
81+
}
82+
},
83+
{ deep: true, flush: 'post' }
84+
)
7185
</script>
7286

7387
<style scoped lang="scss"></style>

src/components/Draggable/index.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<Icon
2929
icon="ep:delete"
3030
class="cursor-pointer text-red-5"
31-
v-if="formData.length > 1"
31+
v-if="formData.length > min"
3232
@click="handleDelete(index)"
3333
/>
3434
</el-tooltip>
@@ -69,7 +69,9 @@ const props = defineProps({
6969
// 空的元素:点击添加按钮时,创建元素并添加到列表;默认为空对象
7070
emptyItem: any<unknown>().def({}),
7171
// 数量限制:默认为0,表示不限制
72-
limit: propTypes.number.def(0)
72+
limit: propTypes.number.def(0),
73+
// 最小数量:默认为1
74+
min: propTypes.number.def(1)
7375
})
7476
// 定义事件
7577
const emit = defineEmits(['update:modelValue'])

0 commit comments

Comments
 (0)