请问vue3的v-model绑定方式是否失效?
hopkinson opened this issue · comments
何大小成 commented
写了一个输入的组件,父组件使用v-model:value是失效的。请问双向绑定的实现是不是只能v-model。
父组件:
<Search v-model:value="xxx" />
子组件:
<template>
<div class="flex items-center mx-4 mb-3 bg-gray-700 rounded-sm px-2 py-1 text-gray-300">
<div class="iconfont icon-search"></div>
<input
v-model="newVal"
type="text"
class="flex-1 outline-none bg-transparent border-0 px-2 text-white"
/>
<div v-if="newVal.length" class="iconfont icon-close" @click="handleClear"></div>
</div>
</template>
<script lang="ts" setup>
const props = defineProps({
value: {
type: String,
default: '',
},
})
const emits = defineEmits(['input'])
const newVal = $computed<string>({
get() {
return props.value
},
set(val) {
emits('input', val)
},
})
const handleClear = () => {
emits('input', '')
}
</script>
ZHAO Jin-Xiang commented
Vue 2 has no v-model arguments.
Anthony Fu commented
Use .sync
. This plugin does not polyfil template syntax and it's out-of-scope.
Anthony Fu commented
Use .sync
. This plugin does not polyfil template syntax and it's out-of-scope.