vue-父组件传递参数到子组件


案例:

父组件

<template>
  <div id="app">
    <h1>vuex</h1>
    <h3>count:{{count}}</h3>
    <button @click="count++">+1</button>
    <button @click="count--">-1</button>
    <!--父组件向子组件传递参数-->
    <hello-word :count2="count"></hello-word>
  </div>
</template>

<script>
  import HelloWord from "./components/HelloWord";
  export default {
    name: 'App',
    components:{
      HelloWord
    },
    data() {
      return{
        count: 0
      }
    }
  }
</script>

 

子组件

<template>
  <div>
    <h2>我是子组件</h2>
    <h3>count3:{{count2}}</h3>
  </div>
</template>

<script>
  export default {
    name: "HelloWord",
    props:{
      count2:Number
    }
  }
</script>

<style scoped>

</style>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM