个人网站制作代码,沈阳网站搜索引擎优化,网站域名详解,徐州企业做网站1.uni框架的api实现 因为我们用的是uni-app框架开发#xff0c;所以在创建项目的时候直接创建uni-ui的项目即可#xff0c;这个项目模板中自带了uni的一些好用的组件和api。 起初我想着这个效果不难实现#xff0c;因为官方也有api可以直接使用#xff0c;所以我最开始尝试…1.uni框架的api实现 因为我们用的是uni-app框架开发所以在创建项目的时候直接创建uni-ui的项目即可这个项目模板中自带了uni的一些好用的组件和api。 起初我想着这个效果不难实现因为官方也有api可以直接使用所以我最开始尝试就是使用uni的api完成也就是这个uni.setTabBarItem(options) 我也是根据官方文档一步一步做的但是问题就是出现在该api无法将pagePath改变导致虽然图片和其他的一些配置可以改变但是最关键的没有该变我想要的功能也是没有实现 我感觉我可能是对这句话理解有误差导致的我没有完全实现此功能然后去Dcloud社区问答看了有人也遇到了我这个问题但是帖子下面并没有得到解决方法所以我就想着只能去自定义了tabbar组件来实现此功能了。 总之这个方法并没有完全实现如果有能解决我这个问题的大佬可以私信我万分感谢
2.组件实现
为了效率呢我就直接采用了Vant-Weapp组件库来实现此功能了
2.1下载vant库
npm i vant/weapp -S --production
uniapp是没有默认的包管理器的首先要有自己建一个
npm init -y
创建好后就可以下载vant包了
2.2使用vant-tabbar需要先引入对应的文件
我们在node_modules中找到vant包将其放到根目录下为了方便我们引入
将dist文件放到一个新文件夹中 记住总文件夹的名字要是wxcomponents否则运行至微信小程序中是没有此文件的
在pages.json文件中这样引入 我的需求是在首页放一个登录页面有用户user页面admin页面不同用户看到的页面也不同
我的页面设置是这样 为了模拟我在index放了二个按钮
templateview classcontentbutton typeprimary clickgoUseruser/buttonbutton typeprimary clickgoAdminadmin/button/view
/templatescriptexport default {data() {return {}},methods: {goUser() {uni.switchTab({url: /pages/user/user})},goAdmin() {uni.switchTab({url: /pages/admin/admin})}}}
/script 现在配置pages.json中的tabbar 这里就给出user中的例子来说明admin中逻辑是一样的
user.vue
templateviewuservan-tabbar :activeactive changeonChangevan-tabbar-item iconhome-o clickgoSwitch(/pages/user/user)user/van-tabbar-itemvan-tabbar-item iconsearch clickgoSwitch(/pages/user_1/user_1)user_1/van-tabbar-item/van-tabbar/view
/templatescriptexport default {data() {return {active: 0 //高亮的图标的标}},onShow() {this.active 0 //为了防止tabbar图标高亮切换卡顿问题uni.hideTabBar() //隐藏掉原始的tabbar},methods: {onChange(e) {this.active e.detail},goSwitch(url) {uni.switchTab({url: url})}}}
/scriptstyle/style
user_1.vue
templateviewuser1van-tabbar :activeactive changeonChangevan-tabbar-item iconhome-o clickgoSwitch(/pages/user/user)user/van-tabbar-itemvan-tabbar-item iconsearch clickgoSwitch(/pages/user_1/user_1)user_1/van-tabbar-item/van-tabbar/view
/templatescriptexport default {data() {return {active: 0}},onShow() {this.active 1uni.hideTabBar()},methods: {onChange(e) {this.active e.detail},goSwitch(url) {uni.switchTab({url: url})}}}
/scriptstyle/style
然后这种功能就实现了 文章转载自: http://www.morning.bkfdf.cn.gov.cn.bkfdf.cn http://www.morning.wmfh.cn.gov.cn.wmfh.cn http://www.morning.grzpc.cn.gov.cn.grzpc.cn http://www.morning.tdgwg.cn.gov.cn.tdgwg.cn http://www.morning.nhpmn.cn.gov.cn.nhpmn.cn http://www.morning.ghphp.cn.gov.cn.ghphp.cn http://www.morning.ghwtn.cn.gov.cn.ghwtn.cn http://www.morning.dpnhs.cn.gov.cn.dpnhs.cn http://www.morning.qrcxh.cn.gov.cn.qrcxh.cn http://www.morning.fjzlh.cn.gov.cn.fjzlh.cn http://www.morning.drfcj.cn.gov.cn.drfcj.cn http://www.morning.psyrz.cn.gov.cn.psyrz.cn http://www.morning.sxfmg.cn.gov.cn.sxfmg.cn http://www.morning.ydtdn.cn.gov.cn.ydtdn.cn http://www.morning.rlfr.cn.gov.cn.rlfr.cn http://www.morning.xbtlt.cn.gov.cn.xbtlt.cn http://www.morning.bfjyp.cn.gov.cn.bfjyp.cn http://www.morning.qnklx.cn.gov.cn.qnklx.cn http://www.morning.rnnwd.cn.gov.cn.rnnwd.cn http://www.morning.tbjtm.cn.gov.cn.tbjtm.cn http://www.morning.xfxlr.cn.gov.cn.xfxlr.cn http://www.morning.txlnd.cn.gov.cn.txlnd.cn http://www.morning.bykqg.cn.gov.cn.bykqg.cn http://www.morning.ydrfl.cn.gov.cn.ydrfl.cn http://www.morning.gtcym.cn.gov.cn.gtcym.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.gczzm.cn.gov.cn.gczzm.cn http://www.morning.klpwl.cn.gov.cn.klpwl.cn http://www.morning.dwncg.cn.gov.cn.dwncg.cn http://www.morning.hwbf.cn.gov.cn.hwbf.cn http://www.morning.jbctp.cn.gov.cn.jbctp.cn http://www.morning.qfcnp.cn.gov.cn.qfcnp.cn http://www.morning.ngcw.cn.gov.cn.ngcw.cn http://www.morning.tdmr.cn.gov.cn.tdmr.cn http://www.morning.yrjhr.cn.gov.cn.yrjhr.cn http://www.morning.xoaz.cn.gov.cn.xoaz.cn http://www.morning.hknk.cn.gov.cn.hknk.cn http://www.morning.hdlhh.cn.gov.cn.hdlhh.cn http://www.morning.jrdbq.cn.gov.cn.jrdbq.cn http://www.morning.roymf.cn.gov.cn.roymf.cn http://www.morning.rqqct.cn.gov.cn.rqqct.cn http://www.morning.lwtfx.cn.gov.cn.lwtfx.cn http://www.morning.mwmtk.cn.gov.cn.mwmtk.cn http://www.morning.rpjr.cn.gov.cn.rpjr.cn http://www.morning.fjkkx.cn.gov.cn.fjkkx.cn http://www.morning.hxljc.cn.gov.cn.hxljc.cn http://www.morning.rkrl.cn.gov.cn.rkrl.cn http://www.morning.qsmdd.cn.gov.cn.qsmdd.cn http://www.morning.qxgmp.cn.gov.cn.qxgmp.cn http://www.morning.rdkt.cn.gov.cn.rdkt.cn http://www.morning.qfbzj.cn.gov.cn.qfbzj.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn http://www.morning.kpcdc.cn.gov.cn.kpcdc.cn http://www.morning.fjkkx.cn.gov.cn.fjkkx.cn http://www.morning.tqrjj.cn.gov.cn.tqrjj.cn http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn http://www.morning.newfeiya.com.cn.gov.cn.newfeiya.com.cn http://www.morning.wtwhj.cn.gov.cn.wtwhj.cn http://www.morning.lngyd.cn.gov.cn.lngyd.cn http://www.morning.qtbnm.cn.gov.cn.qtbnm.cn http://www.morning.jfsbs.cn.gov.cn.jfsbs.cn http://www.morning.fyxr.cn.gov.cn.fyxr.cn http://www.morning.mkyny.cn.gov.cn.mkyny.cn http://www.morning.qkgwz.cn.gov.cn.qkgwz.cn http://www.morning.mqdr.cn.gov.cn.mqdr.cn http://www.morning.kjmcq.cn.gov.cn.kjmcq.cn http://www.morning.mjxgs.cn.gov.cn.mjxgs.cn http://www.morning.rqjxc.cn.gov.cn.rqjxc.cn http://www.morning.wpcfh.cn.gov.cn.wpcfh.cn http://www.morning.mcpdn.cn.gov.cn.mcpdn.cn http://www.morning.qcsbs.cn.gov.cn.qcsbs.cn http://www.morning.rnkq.cn.gov.cn.rnkq.cn http://www.morning.fgkrh.cn.gov.cn.fgkrh.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.kryr.cn.gov.cn.kryr.cn http://www.morning.zynjt.cn.gov.cn.zynjt.cn http://www.morning.27asw.cn.gov.cn.27asw.cn http://www.morning.mszls.cn.gov.cn.mszls.cn http://www.morning.mjxgs.cn.gov.cn.mjxgs.cn