关于defineProps
在很多课件里会用解构的方法去接收props,但这样会让prop丢失响应性!
<script setup>
/* ---- 组件通讯 ---- */
const { standingBookMsg, submitCount } = defineProps({
standingBookMsg: {
type: Object,
required: true
},
submitCount: {
type: Number,
required: true
}
})
/* ---- 业务代码 ---- */
console.log(standingBookMsg)
console.log(submitCount)
</script>
所以,我们应该改成这样:
<script setup>
const props = defineProps({
standingBookMsg: {
type: Object,
required: true
},
submitCount: {
type: Number,
required: true
}
})
/* ---- 业务代码 ---- */
console.log(props.standingBookMsg)
console.log(props.submitCount)
</script>
关于defineEmits
emits 就写成数组形式就好了
<script setup>
/* ---- 组件通讯 ---- */
const emit = defineEmits(['modalClose','modalOpen'])
/* ---- 业务代码 ---- */
const modalCloseHandle = () => {
emit('modalClose')
}
const modalOpenHandle = () => {
emit('modalClose')
}
</script>