父組件
<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>