子容器: export default{ props: ['type'], setup(props) { watch(props.type, () => ">
当一个属性更新时,我如何调用一个函数?
父容器:
<div>
<Maintable :type="typeRef" :country="countryRef" />
</div>
子容器:
export default{
props: ['type'],
setup(props)
{
watch(props.type, () => {
console.log('hello')
})
}
此代码得到一个错误:无效的监视源...我怎样才能听到道具的更新?
希望有人能帮我!!:-)
发布于 2021-04-11 18:14:15
尝试将prop from函数作为第一个参数返回:
export default{
props: ['type'],
setup(props)
{
watch(()=>props.type, (newVal) => {
console.log('hello')
})
}
不要使用watch(props.type ),而要使用watch( ()=>props.type,因为()=>props.type是一个返回属性的箭头函数,并且它是watcher属性的参数
https://stackoverflow.com/questions/67048525
复制相似问题