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