vue中子组件需调用父组件通过异步获取的数据

原因:子组件需要调用父组件传过来的数据,如果这个数据是异步从接口里取的,那这个组件在任何生命周期里都取不到,而应该在接口调取后取到。

需要在msg拿到值后才调用组件,然后你在生命周期created里面取到值了。

解决:

父组件:

<parent  v-if='parent_msg' :message="{parent_msg, 'index'}"></parent> 

子组件:

<child>{{this.message.parent_msg}}</child>
<script>
export default {
    props: ["message"]
  }
</script>

猜你喜欢

转载自www.cnblogs.com/renzm0318/p/9854999.html