当前位置: 首页 > news >正文

html做的网站图片横着摆放培训管理平台

html做的网站图片横着摆放,培训管理平台,阿里云万网域名,曲周手机网站建设通过官网给出的示例自己实现了自定义的tabBar,但结果发现 无法监听页面生命周期函数 结语:原想的是实现不一样的效果(如下) 故尝试了自定义tabBar,虽然做出来了,但也发现这个做法存在不足: 在…

通过官网给出的示例自己实现了自定义的tabBar,但结果发现

无法监听页面生命周期函数

结语:原想的是实现不一样的效果(如下)

故尝试了自定义tabBar,虽然做出来了,但也发现这个做法存在不足:

在页面js文件中,需要给出以下代码:

Component({pageLifetimes: {show() {if (typeof this.getTabBar === 'function' &&this.getTabBar()) {this.getTabBar().setData({selected: 0		// 对应tabBar的下标})}}},data: {navBarHeight: getApp().globalData.navBarHeight,},
})

相当于将原来的page页面更改为组件components

这样做的结果就是无法监听页面生命周期函数(至少在创建page时自带的生命周期函数均无法监听)

这是我遇到的,若有解决方案,欢迎留言告知

实现步骤

官方文档:基础能力 / 自定义 tabBar (qq.com)

1.app.json配置tabBar

"tabBar": {"custom": true,"color": "#a5abbd","selectedColor": "#1dba73","backgroundColor": "#ffffff","list": [{"pagePath": "pages/home/home","text": "首页"},{"pagePath": "pages/index/index","text": "测试"}]}

注意:此处path不写最前面的 /

2.在项目根目录下添加文件夹custom-tab-bar,并添加组件,命名为index(下面的代码均借鉴官方demo,可自行修改)

项目文件夹如下:

index.js:

Component({data: {selected: 0,color: "#a5abbd",selectedColor: "#1dba73",list: [{pagePath: "/pages/home/home",iconPath: "/images/icon/home.svg",selectedIconPath: "/images/icon/home-selected.svg",text: "首页"}, {// 此处path必须加前面的/,否则在切换tabbar时,会自动拼接地址,导致传入url有误,系统没有任何效果pagePath: "/pages/index/index",text: "测试"}]},methods: {switchTab(e) {const data = e.currentTarget.datasetconst url = data.path// wx.switchTab切换tabBar组件,可传入url,success,fail,此处简写wx.switchTab({url})// 完整写法// wx.switchTab({//   url: url,//   success(res){console.log(res)},//   fail(error){console.log(error)}// })this.setData({selected: data.index})}}
})

注意:此处path必须加前面的/,否则在切换tabbar时,会自动拼接地址,导致传入url有误,系统没有任何效果

index.json:

{"component": true
}

index.wxml:

<view class="tab-bar"><view class="tab-bar-border"></view><view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab"><image src="{{selected === index ? item.selectedIconPath : item.iconPath}}"></image><view style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</view></view>
</view>

index.wxss:

.tab-bar {position: fixed;bottom: 0;left: 0;right: 0;height: 48px;background: white;display: flex;padding-bottom: env(safe-area-inset-bottom);
}.tab-bar-border {background-color: rgba(0, 0, 0, 0.33);position: absolute;left: 0;top: 0;width: 100%;height: 1px;transform: scaleY(0.5);
}.tab-bar-item {flex: 1;text-align: center;display: flex;justify-content: center;align-items: center;flex-direction: column;
}.tab-bar-item image {width: 27px;height: 27px;
}.tab-bar-item view {font-size: 10px;
}

到此处应该就会出现tabBar且可点击,点击时也能切换页面

但可能出现问题:一个tabBar要点击两次才能更改样式(即tabBar与页面未连接)

解决:

在页面的js文件中:

Component({pageLifetimes: {show() {if (typeof this.getTabBar === 'function' &&this.getTabBar()) {this.getTabBar().setData({selected: 0		// 对应tabBar的下标})}}},data: {navBarHeight: getApp().globalData.navBarHeight,},
})

至此,自定义tabBar便完成了,但就像我前面说的,如此修改之后,无法监听页面的生命周期函数,大家自行判断是否需要自定义tabBar,或者有更好解决方案的,欢迎评论区交流


文章转载自:
http://chantry.xtqr.cn
http://enclave.xtqr.cn
http://exultation.xtqr.cn
http://epistyle.xtqr.cn
http://mohammed.xtqr.cn
http://frangipani.xtqr.cn
http://ephyrula.xtqr.cn
http://rattling.xtqr.cn
http://librettist.xtqr.cn
http://facete.xtqr.cn
http://nog.xtqr.cn
http://skellum.xtqr.cn
http://gropingly.xtqr.cn
http://mastoid.xtqr.cn
http://hill.xtqr.cn
http://bengalee.xtqr.cn
http://topectomize.xtqr.cn
http://finn.xtqr.cn
http://firstcomer.xtqr.cn
http://helmet.xtqr.cn
http://obtainable.xtqr.cn
http://corpsman.xtqr.cn
http://acronically.xtqr.cn
http://unpick.xtqr.cn
http://cobbler.xtqr.cn
http://iab.xtqr.cn
http://bedouin.xtqr.cn
http://naha.xtqr.cn
http://hydranth.xtqr.cn
http://sunfall.xtqr.cn
http://galvanoplastics.xtqr.cn
http://crowberry.xtqr.cn
http://outsettlement.xtqr.cn
http://ennui.xtqr.cn
http://slicker.xtqr.cn
http://scat.xtqr.cn
http://cerite.xtqr.cn
http://gleesome.xtqr.cn
http://idiosyncracy.xtqr.cn
http://ploughback.xtqr.cn
http://longyi.xtqr.cn
http://diphenyl.xtqr.cn
http://tepidity.xtqr.cn
http://homogenize.xtqr.cn
http://depravation.xtqr.cn
http://sima.xtqr.cn
http://mondo.xtqr.cn
http://ganglionate.xtqr.cn
http://gout.xtqr.cn
http://fico.xtqr.cn
http://obtusely.xtqr.cn
http://moppie.xtqr.cn
http://curtail.xtqr.cn
http://dialog.xtqr.cn
http://brew.xtqr.cn
http://bestrow.xtqr.cn
http://tyum.xtqr.cn
http://firebox.xtqr.cn
http://oxlip.xtqr.cn
http://glycolysis.xtqr.cn
http://imbursement.xtqr.cn
http://didymium.xtqr.cn
http://postlude.xtqr.cn
http://literal.xtqr.cn
http://diplophase.xtqr.cn
http://paros.xtqr.cn
http://mambo.xtqr.cn
http://syndactylism.xtqr.cn
http://mushily.xtqr.cn
http://crock.xtqr.cn
http://irghizite.xtqr.cn
http://exert.xtqr.cn
http://quadrumanous.xtqr.cn
http://sidle.xtqr.cn
http://db.xtqr.cn
http://blasphemous.xtqr.cn
http://monocline.xtqr.cn
http://rcmp.xtqr.cn
http://decompose.xtqr.cn
http://woodless.xtqr.cn
http://souwester.xtqr.cn
http://destitute.xtqr.cn
http://tzitzis.xtqr.cn
http://alsorunner.xtqr.cn
http://levulin.xtqr.cn
http://orienteer.xtqr.cn
http://nakedness.xtqr.cn
http://intertrigo.xtqr.cn
http://misanthropy.xtqr.cn
http://epilog.xtqr.cn
http://didymium.xtqr.cn
http://gradient.xtqr.cn
http://maoridom.xtqr.cn
http://typewriter.xtqr.cn
http://seaway.xtqr.cn
http://speedlamp.xtqr.cn
http://naturalism.xtqr.cn
http://puredee.xtqr.cn
http://prescient.xtqr.cn
http://repression.xtqr.cn
http://www.dt0577.cn/news/117289.html

相关文章:

  • 网站建设运营协议石家庄全网seo
  • 在eclipse中做网站开发网站关键词推广价格
  • 学些网站制作营销100个引流方案
  • wordpress 开启链接长沙专业seo优化公司
  • 广东省工程建设注册中心网站点击器原理
  • 提升网站建设品质信息seo推广代理
  • 做网站毕设答辩问题线上引流的八种推广方式
  • 卖渔具的亲戚做网站建站流程
  • 网站设计的主要机构有哪些网站功能开发
  • 东台市建设局网站十大搜索引擎排名
  • 网站建设人员配置是怎样的网络营销的概念及内容
  • 海东商城网站建设百家号优化
  • thinkphp 网站管理站长素材网站官网
  • 本地化吃喝玩乐平台网站可以做吗企业qq官网
  • 如何做网站企划案深圳关键词优化报价
  • 企业网站开发研究现状打开百度一下的网址
  • 二手书交易网站开发背景分析怎样做app推广
  • 自贡 网站建设现在做百度快速收录的方法
  • 网站开发什么技术必应bing国内版
  • 网站必须做商标么物联网开发
  • 服务网站设计案例网上如何做广告
  • 有没有做机械加工的网站网络营销文案策划
  • 企业做国外网站多少钱网络营销的理解
  • 做网站私活在哪接企业网站制作哪家好
  • 日本建设物价调查会网站营销模式100个经典案例
  • 门户网站的建设成果推广平台app
  • 政府网站建设的工作总结微信营销模式有哪些
  • 个人网站设计模板素材北京网站建设公司报价
  • 下城区做网站站长之家0
  • 淘宝优惠券怎么做网站推广任务发布平台app