1.在根目录下创建一个component文件夹
2.在component文件夹穿件一个文件夹(放一般组件 名字为一般组件名字)
3.鼠标右键一般组件文件夹选择==>新建Component 一般组件便创建完成
4.在路由组件json中引入
"usingComponents": {
"banner": "../../component/banner/banner",
},
5.在路由组件WXML中使用(父传子)
<banner arr="{
{arr}}" ></banner>
6.在一般组件js文件中接收
properties: {
arr: {
type: Array
}
},
7.在一般组件wxml文件中使用
<swiper indicator-dots="true" indicator-active-color="red" autoplay="true" spaceBetween="30rpx">
<block wx:for="{
{arr}}" wx:key="index">
<swiper-item>
<image src="{
{item.imageUrl}}" style="width:100%;height:100%"></image>
</swiper-item>
8.子传父(分发事件方式)
<view bindtap="send">点击传递给父组件</view>
9.子组件js文件中
methods: {
send() {
this.triggerEvent('send',this.data.info)
}
}
10.父组件中定义事件
<view bindsent="sent"></view>
11.父组件中js文件中
sent(e){
console.log(e.detail)
},
12.额外(子组件生命周期)
methods: {
},
ready(){
}