Skip to content

Commit 6edd64f

Browse files
committed
feat: DictTag组件加字符串分隔符props,更灵活定义split字符串的分隔符
1 parent c015b2e commit 6edd64f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/DictTag/src/DictTag.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export default defineComponent({
1515
value: {
1616
type: [String, Number, Boolean, Array],
1717
required: true
18+
},
19+
// 字符串分隔符 只有当 props.value 传入值为字符串时有效
20+
sepSymbol: {
21+
type: String as PropType<string>,
22+
default: ','
1823
}
1924
},
2025
setup(props) {
@@ -23,9 +28,9 @@ export default defineComponent({
2328
if (isNumber(props.value)) {
2429
return [String(props.value)]
2530
}
26-
// 2.是字符串(进一步判断是否有','
31+
// 2.是字符串(进一步判断是否有包含分隔符号 -> props.sepSymbol
2732
else if (isString(props.value)) {
28-
return props.value.includes(',') ? props.value.split(',') : [String(props.value)]
33+
return props.value.split(props.sepSymbol)
2934
}
3035
// 3.数组
3136
else if (isArray(props.value)) {

0 commit comments

Comments
 (0)