1、父组件给子组件通过 props 传值,第一次接收不到怎么处理?
示例代码
父组件:
<template>
<child :params='form'></child>
</template>
<script>
export default {
data() {
return {
form: {}
}
},
methods: {
getParams(val) {
this.form = val
}
}
}
</script>
子组件:
<template>
<div>
{{params}}
</div>
</template>
<script>
export default {
props:{
params: {
type: Object,
default: {}
}
}
}
</script>
示例代码上的 params 第一次会取不到值 第二次就可以了
props
的type
是String
默认值是Object
控制台没给你报错吗?试下