小程序tarbar自定义组件

第一步:建立一个文件夹里面放置组件(tabbar为组件)

第二步编辑:

wxml:

<view class='allfooter'>

<view class='footer-one'>

<view class='foot-img' bindtap='change1'>

<image src='{{tarbar.shouye.active?"照片1":"照片2"}}'></image>

<text>首页</text>

</view>

<view class='foot-img' bindtap='change2'>

<image src='{{tarbar.shanghu.active?"照片1":"照片2"}}'></image>

<text>商户</text>

</view>

<view class='foot-img'>

<image src='中间的照片' bindtap='dowhat'></image>

</view>

<view class='foot-img' bindtap='change3'>

<image src='"照片1":"照片2"}}'></image>

<text>停车</text>

</view>

<view class='foot-img' bindtap='change4'>

<image src='{{tarbar.wode.active?"照片1":"照片2"}'></image>

<text>我的</text>

</view>

</view>

<view class='footer-two' wx:if ="{{show}}"></view>

</view>

 

wxss:

.allfooter{

width: 100%;

position: fixed;

bottom: 0;

left: 0;

}

.allfooter .footer-one{

width: 100%;

height: 10vh;

}

.allfooter .footer-two{

width: 100%;

height: 60rpx;

}

.allfooter .footer-one .foot-img{

width: 20%;

height: 10vh;

float: left;

text-align: center;

position: relative

 

}

.allfooter .footer-one .foot-img image{

width: 44rpx;

height: 44rpx;

margin-top: 20rpx;

}

.allfooter .footer-one .foot-img text{

font-size:24rpx;

display: block

}

.allfooter .footer-one .foot-img:nth-child(3) image{

width: 150rpx;

height: 150rpx;

position: absolute;

left: 0;

right: 0;

bottom: 30rpx;

margin:auto;

}

 

js:

Component({

/**

* 组件的属性列表

*/

properties: {

 

},

 

/**

* 组件的初始数据

*/

data: {

        tarbar:{

                   shouye:{

                                 name:"pages/index/index",

                                 active:false

                   },

                  shanghu: {

                              name: "pages/logs/logs",

                              active: false

                  },

                  tingche: {

                               name: "",

                              active: false

                   },

                 wode: {

                           name: "",

                           active: false

                           }

            }

},

 

/**

* 组件的方法列表

*/

methods: {

               //点击跳转

              change1(){

                             wx.redirectTo({

                                         url: "/"+this.data.tarbar.shouye.name,

                              })

               },

},

 

ready(){

               var that =this

               //获取当前页面

               console.log(getCurrentPages()[0].route)

               for (var x in this.data.tarbar) {

                           console.log(this.data.tarbar[x])

                           if (this.data.tarbar[x].name == getCurrentPages()[0].route) {

                                  var param = this.data.tarbar

                                  param[x].active = true

                                  this.setData({

                                          tarbar: param

                                  })

                         }

                     }

               }

            })

 

第三步 :全局配置(在app.json中)

第四步:使用

   在需要使用的wxml中添加    <tabbar></tabbar> 标签

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值