🐛(component): 修复 select 如果存在 default children, 优先代替 label 属性
This commit is contained in:
		
							parent
							
								
									9e061c6fce
								
							
						
					
					
						commit
						daf5264f35
					
				@ -18,6 +18,7 @@ import {
 | 
			
		||||
  watch,
 | 
			
		||||
  nextTick,
 | 
			
		||||
  onUnmounted,
 | 
			
		||||
  h,
 | 
			
		||||
} from "vue";
 | 
			
		||||
import { LayIcon } from "@layui/icons-vue";
 | 
			
		||||
import LayInput from "../input/index.vue";
 | 
			
		||||
@ -79,12 +80,15 @@ var timer: any;
 | 
			
		||||
const getOption = (nodes: VNode[]) => {
 | 
			
		||||
  nodes
 | 
			
		||||
    ?.filter((item: VNode) => {
 | 
			
		||||
      console.log(JSON.stringify(item));
 | 
			
		||||
      return item.children != "v-if";
 | 
			
		||||
    })
 | 
			
		||||
    ?.map((item: VNode) => {
 | 
			
		||||
      let component = item.type as Component;
 | 
			
		||||
      if (component.name === LaySelectOption.name) {
 | 
			
		||||
        if(item.children) {
 | 
			
		||||
          // @ts-ignore
 | 
			
		||||
          item.props.label = item.children.default()[0].children;
 | 
			
		||||
        }
 | 
			
		||||
        options.value.push(item.props);
 | 
			
		||||
      } else {
 | 
			
		||||
        getOption(item.children as VNode[]);
 | 
			
		||||
 | 
			
		||||
@ -13,10 +13,11 @@ import {
 | 
			
		||||
  WritableComputedRef,
 | 
			
		||||
  Ref,
 | 
			
		||||
  onMounted,
 | 
			
		||||
  useSlots
 | 
			
		||||
} from "vue";
 | 
			
		||||
 | 
			
		||||
export interface LaySelectOptionProps {
 | 
			
		||||
  label: string;
 | 
			
		||||
  label?: string;
 | 
			
		||||
  value: string | number | object;
 | 
			
		||||
  disabled?: boolean;
 | 
			
		||||
  keyword?: string;
 | 
			
		||||
@ -29,9 +30,7 @@ const props = withDefaults(defineProps<LaySelectOptionProps>(), {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const openState: Ref<boolean> = inject("openState") as Ref<boolean>;
 | 
			
		||||
const selectedValue: WritableComputedRef<any> = inject(
 | 
			
		||||
  "selectedValue"
 | 
			
		||||
) as WritableComputedRef<any>;
 | 
			
		||||
const selectedValue: WritableComputedRef<any> = inject("selectedValue") as WritableComputedRef<any>;
 | 
			
		||||
const searchValue: Ref<string> = inject("searchValue") as Ref<string>;
 | 
			
		||||
const selectRef: Ref<HTMLElement> = inject("selectRef") as Ref<HTMLElement>;
 | 
			
		||||
const multiple: ComputedRef = inject("multiple") as ComputedRef;
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,7 @@
 | 
			
		||||
  <lay-select v-model="value" placeholder="请选择">
 | 
			
		||||
    <lay-select-option :value="1" label="学习"></lay-select-option>
 | 
			
		||||
    <lay-select-option :value="2" label="编码"></lay-select-option>
 | 
			
		||||
    <lay-select-option :value="3" v-if="true" label="运动"></lay-select-option>
 | 
			
		||||
    <lay-select-option :value="3" v-if="true">运动</lay-select-option>
 | 
			
		||||
  </lay-select>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user