[新增] selectOption 支持传入keyword属性用于自定义关键词查询内容

This commit is contained in:
castleiMac
2022-04-03 17:44:55 +08:00
parent 1cdfa5d112
commit 18ee8db079
2 changed files with 39 additions and 3 deletions

View File

@@ -7,16 +7,19 @@ export default {
<script setup lang="ts">
import LayCheckbox from "../checkbox";
import { SelectItem, SelectItemHandle, SelectItemPush } from "../../types";
import { computed, inject, onMounted, Ref } from "vue";
import { computed, inject, onMounted, Ref, ref } from "vue";
export interface LaySelectOptionProps {
value: string | null | undefined;
label?: string;
label: string;
keyword?: string;
disabled?: boolean;
}
const props = withDefaults(defineProps<LaySelectOptionProps>(), {
disabled: false,
keyword: "",
label: ""
});
const selectItemHandle = inject("selectItemHandle") as SelectItemHandle;
@@ -57,15 +60,18 @@ const callSelectItemPush = function () {
// @ts-ignore
selectItemPush(item);
};
const search = ref("")
onMounted(() => {
search.value = props.keyword || props.label
callSelectItemPush();
selected.value && callSelectItemHandle();
});
</script>
<template>
<dd
v-show="keyword ? props.label.includes(keyword) : true"
v-show="keyword ? search.includes(keyword) : true"
:value="value"
:class="[{ 'layui-this': selected }, { 'layui-disabled': disabled }]"
@click="selectHandle"