zoukankan      html  css  js  c++  java
  • vue父传子

    父组件传递数据给子组件用props,父组件中使用子组件,子组件用props接收父组件数据。

    Home父组件代码:

    <template>
    <div>
         {{test}}
         <!-- 使用子组件,绑定父组件数据数据 -->
        <Child :test="test"></Child>
    </div>
    </template>
    <script>
    // import子组件
    import Child from './Child.vue'
    export default {
      name: "Home",
      //components引入子组件
      components:{
          Child
      },
      data () {
        return {
            test:123
        };
      }
    }
    </script>
    <style lang="css" scoped>
    </style>

    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>
  • 相关阅读:
    【每天一道PAT】1001 A+B Format
    C++ STL总结
    开篇
    happen-before原则
    java多线程的状态转换以及基本操作
    集合初始容量
    fail-fast机制
    Stack
    Iterator
    Vector
  • 原文地址:https://www.cnblogs.com/luguankun/p/10312095.html
Copyright © 2011-2022 走看看