uniapp父子組件之間傳值


父組件

<template>
  <view class="parent-comm">
    <itemcomm :msg="list"></itemcomm> //子組件   :msg="list" 這個是傳值給子組件,msg字段可自己取名,但子組件上必須和父組件上的統一。
  </view>
</template>

<script>
  import itemcomm from './test0301.vue' //子組件
  export default {
    data() {
      return {
        list: {
          "a": 100,
          "b": 200,
          "c": 300
        }
      }
    },
    components: {
      itemcomm //子組件
    },
    methods: {

    }
  }
</script>

<style>
</style>

子組件

<template>
  <view class="node-comm">
    <text>{{msg.a}}</text>//顯示父組件傳過來的值
    <text>{{msg.b}}</text>//顯示父組件傳過來的值
    <text>{{msg.c}}</text>//顯示父組件傳過來的值
  </view>
</template>

<script>
  export default{
    props:{
      msg:{  //接收父組件傳過來的值
        type:Object,
        default:{}
      }
    }  
  }
</script>

<style>
</style>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM