分享

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

 精品唯居 2021-11-06

案例:

父组件

<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>

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多