父组件传递数据给子组件用 props, 父组件中使用子组件, 子组件用 props 接收父组件数据.
Home 父组件代码:
Child 子组件代码:
- <template>
- <div>
- <!-- 使用子组件数据 -->
- {{test}}
- </div>
- </template>
- <script>
- export default {
- name: "Child",
- // props 使用获取父组件数据
- props:["test"],
- data () {
- return {
- };
- },
- created(){
- // 使用子组件数据
- console.log(this.test);
- }
- }
- </script>
- <style lang="css" scoped>
- </style>
来源: http://www.bubuko.com/infodetail-2931787.html