[新增] select 组件
This commit is contained in:
parent
1ca3fae28e
commit
8f3b104c8b
@ -198,9 +198,9 @@ export default {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<lay-form>
|
<lay-form>
|
||||||
<lay-select>
|
<lay-select v-model="select">
|
||||||
<lay-select-option>北京</lay-select-option>
|
<lay-select-option value="beijing" label="北京"></lay-select-option>
|
||||||
<lay-select-option>济南</lay-select-option>
|
<lay-select-option value="jinan" label="济南"></lay-select-option>
|
||||||
</lay-select>
|
</lay-select>
|
||||||
</lay-form>
|
</lay-form>
|
||||||
</template>
|
</template>
|
||||||
@ -211,7 +211,10 @@ import { ref } from 'vue'
|
|||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
|
|
||||||
|
const select = ref("jinan")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
select
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,30 @@
|
|||||||
<template>
|
<template>
|
||||||
<select name="city" lay-verify="required">
|
<select :name="name" lay-verify="required">
|
||||||
<option value=""></option>
|
|
||||||
<option value="0">北京</option>
|
|
||||||
<option value="1">上海</option>
|
|
||||||
<option value="2">广州</option>
|
|
||||||
<option value="3">深圳</option>
|
|
||||||
<option value="4">杭州</option>
|
|
||||||
</select>
|
</select>
|
||||||
<div class="layui-unselect layui-form-select" @click="open" :class="[openState?'layui-form-selected':'']">
|
<div class="layui-unselect layui-form-select" @click="open" :class="[openState?'layui-form-selected':'']">
|
||||||
<div class="layui-select-title">
|
<div class="layui-select-title">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="请选择"
|
placeholder="请选择"
|
||||||
value=""
|
:value="selectItem.label"
|
||||||
readonly=""
|
readonly=""
|
||||||
class="layui-input layui-unselect"
|
class="layui-input layui-unselect"
|
||||||
/><i class="layui-edge"></i>
|
/><i class="layui-edge"></i>
|
||||||
</div>
|
</div>
|
||||||
<dl class="layui-anim layui-anim-upbit" style="">
|
<dl class="layui-anim layui-anim-upbit" style="">
|
||||||
<dd lay-value="" class="layui-select-tips">请选择</dd>
|
<dd lay-value="" @click="clean" class="layui-select-tips">请选择</dd>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="LaySelect" lang="ts">
|
<script setup name="LaySelect" lang="ts">
|
||||||
import { defineProps, ref } from 'vue'
|
import { defineProps, provide, reactive, ref, watch } from 'vue'
|
||||||
|
|
||||||
const props =
|
const props =
|
||||||
defineProps<{
|
defineProps<{
|
||||||
modelValue?: string
|
modelValue?: string
|
||||||
|
name?: string
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const openState = ref(false)
|
const openState = ref(false)
|
||||||
@ -37,4 +32,21 @@ const openState = ref(false)
|
|||||||
const open = function() {
|
const open = function() {
|
||||||
openState.value = !openState.value
|
openState.value = !openState.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectItem = reactive({label:"",value:props.modelValue});
|
||||||
|
|
||||||
|
provide("selectItem",selectItem);
|
||||||
|
|
||||||
|
// select update 时, 通知 change 事件
|
||||||
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
|
watch(selectItem, function(item) {
|
||||||
|
emit('update:modelValue', item.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const clean = function() {
|
||||||
|
selectItem.value = "";
|
||||||
|
selectItem.label = "";
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,14 +1,31 @@
|
|||||||
<template>
|
<template>
|
||||||
<dd :value="value">
|
<dd :value="value" @click="selectHandle" :class="[selectItem.value === value?'layui-this':'']">
|
||||||
<slot></slot>
|
{{label}}
|
||||||
</dd>
|
</dd>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="LaySelectOption" lang="ts">
|
<script setup name="LaySelectOption" lang="ts">
|
||||||
import { defineProps } from 'vue'
|
import { SelectItem } from '../type'
|
||||||
|
import { defineProps, inject } from 'vue'
|
||||||
|
|
||||||
const props =
|
const props =
|
||||||
defineProps<{
|
defineProps<{
|
||||||
value?: string
|
value?: string
|
||||||
|
label?: string
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
const selectItem = inject("selectItem") as SelectItem
|
||||||
|
|
||||||
|
const selectHandle = function(){
|
||||||
|
selectItem.value = props.value
|
||||||
|
selectItem.label = props.label
|
||||||
|
}
|
||||||
|
|
||||||
|
// init selected
|
||||||
|
|
||||||
|
if(selectItem.value === props.value) {
|
||||||
|
selectItem.value = props.value
|
||||||
|
selectItem.label = props.label
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -1 +1,2 @@
|
|||||||
export * from './public'
|
export * from './public'
|
||||||
|
export * from './select'
|
4
src/module/type/select.ts
Normal file
4
src/module/type/select.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface SelectItem {
|
||||||
|
label?: String,
|
||||||
|
value?: String
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user