微信小程序父组件给子组件传参

1.首先在父组件引入子组件,也需要json中引入

<alertMessage img="{{appMessage.imgSrc}}"></alertMessage>

2.子组件必须必须是Component,正常的是Page

3.在子组件中接收从父组件传来的属性

properties: {
    img: String,
    
},

4.在wxml中使用

<image src="{{img}}" />

5.完成。附上官方文档https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/component.html

原文地址:https://www.cnblogs.com/lude1994/p/13139655.html