前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >uni-app 父组件的参数如何传给子组件

uni-app 父组件的参数如何传给子组件

作者头像
达达前端
发布2019-10-29 17:27:56
4.2K0
发布2019-10-29 17:27:56
举报
文章被收录于专栏:达达前端达达前端

uni-app 如何在组件和组件之间,页面和组件之间相互传值 父组件向子组件传值 通过props来实现,子组件通过props来接收父组件传过来的值! 父组件中: 第一步:引入子组件;

代码语言:javascript
复制
import device from './components/device.vue'
import battery from './components/battery.vue'

在components中对子组件进行注册

代码语言:javascript
复制
components: {
            device,
            battery
},

以标签的形式载入;通过数据绑定的形式进行传值

代码语言:javascript
复制
<device ref="device" :id="business-id" v-show="active == 'device'">
</device>
<battery ref="battery" :id="business-id" v-show="active == 'battery'">
</battery>

父组件index.vue

代码语言:javascript
复制
<template>
    <view class="content">
        <son-show :reUserInfo="userInfo"></son-show>
    </view>
</template>
 
<script>
    import sonShow from '../../component/son.vue';
    export default {
        components: {
            sonShow
        },
        data() {
            return {
                userInfo: [{
                        "userName": "",
                        "age": ""
                    },
                    {
                        "userName": "",
                        "age": ""
                    }
                ]
            }
        }
    }
</script>
代码语言:javascript
复制
<template>
    <view class="">
        <block  v-for="(item,index) in reciveUserInfo" :key="index">
            <view class="mesg">
                <text>{{item.userName}}</text>
                <text>{{item.age}}</text>
            </view>
        </block>
    </view>
</template>
 
<script>
    export default{
        props:["reciveUserInfo"],
    }
</script>

子组件向父组件传值 父组件index.vue

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.10.29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档