vue组件的props定义真的不能偷懒,之前没写type类型验证,传错值debug半天。还有组件名别随便起,起个有意义的名字后面维护的时候能救命。之前搞了个组件叫Box1自己都忘了是干啥的,后来改成SearchInput瞬间清晰多了
<template>
<div class="search-input">
<input v-model="keyword" @input="handleInput" />
</div>
</template>
<script setup>
import { ref, defineProps, defineEmits } from 'vue'
const props = defineProps({
placeholder: {
type: String,
default: '请输入...'
}
})
const emit = defineEmits()
const keyword = ref('')
const handleInput = () => {
emit('search', keyword.value)
}
</script>
登录/注册