在nuxt.config.ts中配置
vite: {
vue: {
script: {
defineModel: true,
propsDestructure: true,
}
}
},
然后在子组件中使用
const paginationIndex = defineModel<number>()
在父组件中使用
<AppPagination v-model="paginationIndex" class="pagination"></AppPagination>
<script setup lnag='ts'>
const paginationIndex = ref(2)
watch(paginationIndex, (newValue,oldValue) =>{
console.log(newValue)
})
</script>
父组件可以使用watch来监听子组件修改之后的值,可以做出相应的操作,不得不说defineModel真是太好用了!!!!
顺便帮我怎么传对象结构啊???求助!!!