feat: 增加清空搜索框的按钮 #18

This commit is contained in:
ZiuChen 2022-08-18 16:46:52 +08:00
parent d5f5d123d5
commit bc7d869a3b
2 changed files with 20 additions and 0 deletions

View File

@ -1,6 +1,7 @@
<template>
<div class="clip-search">
<input v-model="filterText" type="text" placeholder="🔍 检索剪贴板历史" />
<span v-show="filterText" @click="clear" class="clip-search-suffix"></span>
</div>
</template>
@ -16,11 +17,14 @@ const filterText = ref('')
const emit = defineEmits(['update:modelValue'])
// filterText modelValue
watch(filterText, (val) => emit('update:modelValue', val))
// modelValue filterText
watch(
() => props.modelValue,
(val) => (filterText.value = val)
)
const clear = () => emit('update:modelValue', '')
</script>
<style lang="less" scoped>

View File

@ -18,4 +18,20 @@
color: @text-color-lighter;
}
}
.clip-search-suffix {
text-align: center;
position: absolute;
right: 20px;
top: 18px;
font-size: 13px;
padding: 2px;
width: 20px;
height: 20px;
background-color: @nav-bg-color;
border-radius: 20px;
cursor: pointer;
&:hover {
background-color: @nav-hover-bg-color;
}
}
}