子组件
<script setup lang="ts">
import { watch, watchEffect } from 'Vue'
type IListObj = Record<string, string | number | Array<IListObj>>
interface Props {
modelValue: string | number | string[] | number[],
list: Array<IListObj>
}
const props = withDefaults(defineProps<Props>(), {
modelValue: '',
list() {
return []
}
})
watch(() => props, (val) => console.log(val))
watch(() => props.list, (val) => console.log(val))
watchEffect(() => {
console.log('modelValue: ', props.modelValue)
console.log('list: ', props.list)
})
父组件:
<child v-model="xx" :list="list">
当 xx 或者 list 变化时,子组件中的 watch 和 watchEffect 都不会触发
4***@qq.com
奥,我是因为 prop 名称的格式问题, 不要用 :data-source="xx", 用驼峰的:dataSource="xx", 小程序就表现一致了
2022-10-28 10:16