🐛 修复 icon-picker 选择图标自动隐藏内容

This commit is contained in:
就眠儀式
2021-12-17 00:07:15 +08:00
parent 43e4ab7ade
commit 7873134d81
3 changed files with 60 additions and 49 deletions

View File

@@ -1,3 +1,49 @@
<script lang="ts">
export default {
name: "LayDropdown"
}
</script>
<script setup lang="ts">
import { defineProps, provide, ref, watch } from 'vue'
import { useClickOutside } from '@layui/hooks-vue'
const dropdownRef = ref<null | HTMLElement>(null)
const isClickOutside = useClickOutside(dropdownRef)
export interface LayDropdownProps {
trigger?: string
}
const props = withDefaults(defineProps<LayDropdownProps>(),{
trigger: 'click',
})
const openState = ref(false)
const open = function () {
openState.value = true
}
const hide = function () {
openState.value = false
}
const toggle = function () {
openState.value = !openState.value
}
watch(isClickOutside, () => {
if (isClickOutside.value) {
openState.value = false
}
})
provide('openState', openState)
defineExpose({ open, hide, toggle });
</script>
<template>
<div
v-if="trigger === 'click'"
@@ -30,43 +76,4 @@
</ul>
</dl>
</div>
</template>
<script setup name="LaySelect" lang="ts">
import { defineProps, provide, ref, watch } from 'vue'
import { useClickOutside } from '@layui/hooks-vue'
const dropdownRef = ref<null | HTMLElement>(null)
const isClickOutside = useClickOutside(dropdownRef)
const props = withDefaults(
defineProps<{
trigger?: string
}>(),
{
trigger: 'click',
}
)
const openState = ref(false)
const open = function () {
openState.value = true
}
const hide = function () {
openState.value = false
}
const toggle = function () {
openState.value = !openState.value
}
watch(isClickOutside, () => {
if (isClickOutside.value) {
openState.value = false
}
})
provide('openState', openState)
</script>
</template>