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