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

uniapp引入微信小程序版本VantUI,使用VantUI的自定义tabbar,并解决自定义tabbar出现闪烁的情况

视频教程地址:https://www.bilibili.com/video/BV13m41167iG

1.uniapp引入微信小程序版本VantUI

去vant官网下载源码,源码放在github,自行去下载下来
https://vant-contrib.gitee.io/vant-weapp/#/home

在这里插入图片描述

  • 在pages.json的globalStyle里面注册组件
	"globalStyle": {"navigationBarTextStyle": "black","navigationBarTitleText": "uni-app","navigationBarBackgroundColor": "#F8F8F8","backgroundColor": "#F8F8F8",//全局注册方式1 单个组件"usingComponents": {"van-tabbar": "/wxcomponents/vant/dist/tabbar/index","van-tabbar-item": "/wxcomponents/vant/dist/tabbar-item/index","van-search": "/wxcomponents/vant/dist/search/index","van-dialog": "/wxcomponents/vant/dist/dialog/index","van-field": "/wxcomponents/vant/dist/field/index","van-cell-group": "/wxcomponents/vant/dist/cell-group/index","van-divider": "/wxcomponents/vant/dist/divider/index","van-cell": "/wxcomponents/vant/dist/cell/index","van-button": "/wxcomponents/vant/dist/button/index","van-action-sheet": "/wxcomponents/vant/dist/action-sheet/index","van-uploader": "/wxcomponents/vant/dist/uploader/index","van-notify": "/wxcomponents/vant/dist/notify/index","van-icon": "/wxcomponents/vant/dist/icon/index","van-switch": "/wxcomponents/vant/dist/switch/index","van-radio": "/wxcomponents/vant/dist/radio/index","van-radio-group": "/wxcomponents/vant/dist/radio-group/index","van-popup": "/wxcomponents/vant/dist/popup/index",// "van-overlay": "/wxcomponents/vant/dist/overlay/index","van-cascader": "/wxcomponents/vant/dist/cascader/index","van-card": "/wxcomponents/vant/dist/card/index","van-submit-bar": "/wxcomponents/vant/dist/submit-bar/index","van-notice-bar": "/wxcomponents/vant/dist/notice-bar/index","van-checkbox": "/wxcomponents/vant/dist/checkbox/index","van-empty": "/wxcomponents/vant/dist/empty/index","van-steps": "/wxcomponents/vant/dist/steps/index","van-toast": "/wxcomponents/vant/dist/toast/index"},"app-plus": {"softinputNavBar": "none","scrollIndicator": "none"}},

在这里插入图片描述

  • 引入CSS样式
@import "/wxcomponents/vant/dist/common/index.wxss";

在这里插入图片描述

  • 在页面中引入按钮组件
<van-button type="primary">主要按钮</van-button>

在这里插入图片描述

2.自定义tabbar(点击跳转的时候tabbar会出现闪烁)

  • 设置自定义tabbar样式
	/* 隐藏原生tabbar */.uni-tabbar-bottom{display: none !important;}/* 使用vant-ui tabbar */.van-tabbar-bottom{position: fixed !important;bottom: 0 !important;width: 100% !important;z-index: 99999999 !important;border-top: 0 solid #ebedf0 !important;border-bottom-style: hidden !important;}.van-hairline--top-bottom:after{border-top-width: 1px !important;border-right-width: 0px !important;border-bottom-width: 0px !important;border-left-width: 0px !important;}

在这里插入图片描述

  • 编写自定义tabbar组件
<template><view><view class="van-tabbar-bottom"><van-tabbar :active="active" @change="onChange" :border="true" active-color="#898dda" inactive-color="#9c9c9c"><van-tabbar-item icon="chat-o">首页</van-tabbar-item><van-tabbar-item icon="contact">我的</van-tabbar-item></van-tabbar></view></view>
</template><script>import Toast from '@/wxcomponents/vant/dist/toast/toast';export default {name: "tabbar",data() {return {tabbarList: {0: "/pages/index/index",1: "/pages/my/my",},}},props: {active: Number},methods: {onChange(index) {uni.switchTab({url: this.tabbarList[index.detail]})},}}
</script><style scoped></style>

在这里插入图片描述

  • pages.json中设置tabbar
	"tabBar": {"custom": true,// 隐藏原生tabar 仅h5和微信小程序"height":"0.1rpx",// app 隐藏原生tabar需要将高度设置成最小0.1px rpx"borderStyle":"white","list": [{"pagePath": "pages/index/index"},{"pagePath": "pages/my/my"}]},

在这里插入图片描述

  • 在index.vue页面中调用自定义的tabbar
<template><view class="content">首页<van-button type="primary">主要按钮</van-button><view class="foot"><tabbar :active="0"></tabbar></view></view></template><script>import tabbar from "@/components/tabbar/tabbar"export default {data() {return {title: 'Hello'}},onLoad() {},methods: {}}
</script><style></style>

在这里插入图片描述
在my.vue页面中调用自定义的tabbar

<template><view>我的<view class="foot"><tabbar :active="1"></tabbar></view></view></template><script>import tabbar from "@/components/tabbar/tabbar"export default {data() {return {}},methods: {}}
</script><style></style>

在这里插入图片描述

  • 成功显示

在这里插入图片描述

完整的pages.json配置

{"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages{"path": "pages/index/index","style": {"navigationBarTitleText": "index"}},{"path" : "pages/my/my","style" :                                                                                    {"navigationBarTitleText": "my"}}],"globalStyle": {"navigationBarTextStyle": "black","navigationBarTitleText": "uni-app","navigationBarBackgroundColor": "#F8F8F8","backgroundColor": "#F8F8F8",//全局注册方式1 单个组件"usingComponents": {"van-tabbar": "/wxcomponents/vant/dist/tabbar/index","van-tabbar-item": "/wxcomponents/vant/dist/tabbar-item/index","van-search": "/wxcomponents/vant/dist/search/index","van-dialog": "/wxcomponents/vant/dist/dialog/index","van-field": "/wxcomponents/vant/dist/field/index","van-cell-group": "/wxcomponents/vant/dist/cell-group/index","van-divider": "/wxcomponents/vant/dist/divider/index","van-cell": "/wxcomponents/vant/dist/cell/index","van-button": "/wxcomponents/vant/dist/button/index","van-action-sheet": "/wxcomponents/vant/dist/action-sheet/index","van-uploader": "/wxcomponents/vant/dist/uploader/index","van-notify": "/wxcomponents/vant/dist/notify/index","van-icon": "/wxcomponents/vant/dist/icon/index","van-switch": "/wxcomponents/vant/dist/switch/index","van-radio": "/wxcomponents/vant/dist/radio/index","van-radio-group": "/wxcomponents/vant/dist/radio-group/index","van-popup": "/wxcomponents/vant/dist/popup/index",// "van-overlay": "/wxcomponents/vant/dist/overlay/index","van-cascader": "/wxcomponents/vant/dist/cascader/index","van-card": "/wxcomponents/vant/dist/card/index","van-submit-bar": "/wxcomponents/vant/dist/submit-bar/index","van-notice-bar": "/wxcomponents/vant/dist/notice-bar/index","van-checkbox": "/wxcomponents/vant/dist/checkbox/index","van-empty": "/wxcomponents/vant/dist/empty/index","van-steps": "/wxcomponents/vant/dist/steps/index","van-toast": "/wxcomponents/vant/dist/toast/index"},"app-plus": {"softinputNavBar": "none","scrollIndicator": "none"}},"tabBar": {"custom": true,// 隐藏原生tabar 仅h5和微信小程序"height":"0.1rpx",// app 隐藏原生tabar需要将高度设置成最小0.1px rpx"borderStyle":"white","list": [{"pagePath": "pages/index/index"},{"pagePath": "pages/my/my"}]},"uniIdRouter": {}
}

3.自定义tabbar(解决点击跳转的时候tabbar出现闪烁)

  • 互换位置,把tabbar写成页面,index和my写成组件,然后在tabbar页面中引入index和my组件切换即可

···

  • pages.json中去掉tabbar配置,在pages:[]配置页面中只需要配置tabbar这个页面即可

在这里插入图片描述

  • tabbar.vue页面
<template><view><!-- 组件页面 --><view class="component-page"><index v-if="active == 0"></index><my v-if="active == 1"></my></view><!-- tabbar --><view class="van-tabbar-bottom"><van-tabbar :active="active" @change="onChange" :border="true" active-color="#898dda" inactive-color="#9c9c9c"><van-tabbar-item icon="chat-o">首页</van-tabbar-item><van-tabbar-item icon="contact">我的</van-tabbar-item></van-tabbar></view></view></template><script>import index from '@/components/index/index.vue'import my from '@/components/my/my.vue'export default {name: "tabbar",data() {return {active: 0}},components:{index,my},methods: {onChange(index) {console.log(index.detail)this.active = index.detail},}}
</script><style></style>

在这里插入图片描述

  • index.vue组件
<template><view>我是index</view>
</template><script>export default {name:"index",data() {return {};}}
</script><style></style>

在这里插入图片描述

  • my.vue组件
<template><view>我是my</view>
</template><script>export default {name:"my",data() {return {};}}
</script><style></style>

在这里插入图片描述

  • 完美解决闪烁问题

在这里插入图片描述

值得注意的一点时,如果这样子修改,可能会造成生命周期的改变,所以写的时候需要多注意一下

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 代码随想录阅读笔记-二叉树【二叉搜索树转换为累加树】
  • 用vue.js写案例——ToDoList待办事项 (步骤和全码解析)
  • React - 你使用过高阶组件吗
  • WKWebView的使用
  • 安卓远离手机app
  • 自然语言处理-词向量模型-Word2Vec
  • 如何从应用商店Microsoft Store免费下载安装HEVC视频扩展插件
  • 华为OD机试 - 堆栈中的剩余数字(Java JS Python C C++)
  • 【进阶版】基于KubeAdm搭建多节点K8S集群,并使用Rancher导入K8S集群
  • JavaScript中如何理解堆栈溢出和内存泄漏
  • 漫谈:C、C++字符串的困局
  • 【go从入门到精通】作用域,包详解
  • Macos 部署自己的privateGpt(2024-0404)
  • python 08Pandas
  • 想做产品经理,应该选择什么专业?
  • 07.Android之多媒体问题
  • co.js - 让异步代码同步化
  • Flannel解读
  • If…else
  • Java Agent 学习笔记
  • java2019面试题北京
  • miaov-React 最佳入门
  • mysql 5.6 原生Online DDL解析
  • nginx 配置多 域名 + 多 https
  • PHP 7 修改了什么呢 -- 2
  • windows-nginx-https-本地配置
  • 分布式熔断降级平台aegis
  • 前端面试之闭包
  • 双管齐下,VMware的容器新战略
  • 腾讯大梁:DevOps最后一棒,有效构建海量运营的持续反馈能力
  • 学习笔记TF060:图像语音结合,看图说话
  • 源码安装memcached和php memcache扩展
  • 智能合约Solidity教程-事件和日志(一)
  • [Shell 脚本] 备份网站文件至OSS服务(纯shell脚本无sdk) ...
  • 好程序员web前端教程分享CSS不同元素margin的计算 ...
  • ​Benvista PhotoZoom Pro 9.0.4新功能介绍
  • ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
  • # Pytorch 中可以直接调用的Loss Functions总结:
  • #【QT 5 调试软件后,发布相关:软件生成exe文件 + 文件打包】
  • (Charles)如何抓取手机http的报文
  • (webRTC、RecordRTC):navigator.mediaDevices undefined
  • (二)linux使用docker容器运行mysql
  • (小白学Java)Java简介和基本配置
  • (转)MVC3 类型“System.Web.Mvc.ModelClientValidationRule”同时存在
  • **《Linux/Unix系统编程手册》读书笔记24章**
  • ./mysql.server: 没有那个文件或目录_Linux下安装MySQL出现“ls: /var/lib/mysql/*.pid: 没有那个文件或目录”...
  • .Net 6.0 处理跨域的方式
  • .NET 8 中引入新的 IHostedLifecycleService 接口 实现定时任务
  • .net6解除文件上传限制。Multipart body length limit 16384 exceeded
  • .NET连接MongoDB数据库实例教程
  • .NET设计模式(7):创建型模式专题总结(Creational Pattern)
  • .NET值类型变量“活”在哪?
  • @PreAuthorize与@Secured注解的区别是什么?
  • @Transactional类内部访问失效原因详解
  • [ 数据结构 - C++] AVL树原理及实现