1.在compontents新建文件放入

<template>
<section class="tabBar-wrap">
<article class="tabBar-box">
<ul class="tabBar-nav" v-if="navList.length > 0">
<li
class="item"
v-for="(item, index) in navList"
@click="selectNavItem(index,item.pagePath)"
:key="index"
>
<p class="item-images">
<img
:src="selectNavIndex === index ? item.selectedIconPath : item.iconPath"
alt="iconPath"
>
</p>
<p
:class="selectNavIndex === index ? 'item-text item-text-active' : 'item-text' "
>{{item.text}}</p>
</li>
<li v-if="needButton" style="flex: 3">
<div class="submit-box">
<button
:disabled="!handButton"
@click="bindNavigateTo('../pages/index')"
:class="handButton ? 'submit-box-btn submit-box-btn-active' : 'submit-box-btn' "
>{{ btnText }}</button>
</div>
</li>
</ul>
</article>
</section>
</template>
<script>
export default {
props: ["selectNavIndex", "needButton", "handButton", "btnText"],
data() {
return {
navList: [
{
selectedIconPath: "/static/image/delete.png",
iconPath: "/static/image/delete.png",
pagePath: "../index/main",
text: "首页"
},
{
selectedIconPath: "/static/image/delete.png",
iconPath: "/static/image/delete.png",
pagePath: "../index1/main",
text: "发布"
},
{
selectedIconPath: "/static/image/delete.png",
iconPath: "/static/image/delete.png",
pagePath: "../index2/main",
text: "订单"
}
]
};
},
methods: {
selectNavItem(index, pagePath) {
if (index === this.selectNavIndex) {
return false;
}
console.log(index);
if (index == 0 && this.selectNavIndex == -1) {
this.$emit("fetch-index");
}
this.bindViewTap(pagePath);
},
bindNavigateTo(url) {
wx.navigateTo({
url
});
},
bindViewTap(url) {
let page = getCurrentPages();
console.log(page);
wx.reLaunch({
url
});
}
}
};
</script>
<style lang="less" scoped>
.tabBar-box {
position: fixed;
bottom: 0;
width: 100%;
height: 50px;
border-top: 1px solid #eee;
background-color: #f8f8f8;
}
.tabBar-nav {
width: 100%;
display: flex;
.item {
flex: 1;
text-align: center;
}
.item-text {
color: #666;
font-size: 9px;
transition: 0.24s linear;
}
.item-text-active {
color: #f33f3f;
}
.item-images {
width: 21px;
height: 21px;
margin: 4px auto;
text-align: center;
transition: 0.24s linear;
& img {
display: inline;
}
}
}
.submit-box-btn {
position: relative;
z-index: 999;
width: 85%;
height: 90px;
line-height: 90px;
border-radius: 10px;
color: #404040;
font-size: 36px;
border: none;
background-color: #eee;
text-align: center;
border: 1px solid #eee;
}
.submit-box-btn-active {
color: #fff;
border: none;
border: 1px solid #ff6c00;
background-color: #ff6c00;
}
button {
border: none;
outline: none;
}
</style>
 
2.在终端下输入命令    npm i vue-style-loader less-loader css-loader vue-loader less
 
3.在使用的页面引入文件夹

import vueTabBar from "../../components/vueTabBar.vue";
 
4.

components: {
vueTabBar
}
 
5.

<vueTabBar :selectNavIndex="selectNavIndex"></vueTabBar>
 
data中定义

selectNavIndex:0
 
大功告成!!!!

小程序 mpvue自定义底部导航栏的更多相关文章

  1. uniapp 小程序实现自定义底部导航栏(tarbar)

    在小程序开发中,默认底部导航栏很难满足实际需求,好在官方给出了自定义形式,效果如下: 话不多说,直接上代码 1.组件 custom-tarbar.vue文件 <template> < ...

  2. 微信小程序自定义底部导航栏组件+跳转

    微信小程序本来封装有底部导航栏,但对于想自定义样式和方法的开发者来说,这并不是很好. 参考链接:https://github.com/ljybill/miniprogram-utils/tree/ma ...

  3. 小程序配置单个页面导航栏的属性(微信小程序交流群:604788754)

    配置单个页面导航栏的属性: 就在所要配置页面相对应的json文件中写入以下想要设置的属性: { "navigationBarBackgroundColor": "#fff ...

  4. 初尝微信小程序2-Swiper组件、导航栏标题配置

    swiper 滑块视图容器. 很多网页的首页都会有一个滚动的图片模块,比如天猫超市首页,滚动着很多优惠活动的图片,用来介绍优惠内容,以及供用户点击快速跳转到相应页面. Swiper不仅可以滚动图片,也 ...

  5. 微信小程序之自定义底部弹出框动画

    最近做小程序时,会经常用到各种弹框.直接做显示和隐藏虽然也能达到效果,但是体验性太差,也比较简单粗暴.想要美美地玩,添加点动画还是非常有必要的.下面做一个底部上滑的弹框. wxml <view ...

  6. 自定义底部导航栏(tabBar)

    前言如果大家用过微信提供的tabBar就会发现,他的tabBar有很大的局限性.暂且不说样式局限性了,他提供的app.json配置文件中没有function.这也就意味着使用它提供的这个组件,你只能用 ...

  7. 微信小程序开发之tab导航栏

    实现功能: 点击不同的tab导航,筛选数据 UI:   js: data:{ navbar: ['半月维保', '季度维保', '半年维保',"年度维保"],    //count ...

  8. 微信小程序点击顶部导航栏切换样式

    类似这样的效果 <view class='helpCateList'> <!-- 类别 --> <scroll-view class='scroll-view' scro ...

  9. 微信小程序从零开始开发步骤(三)底部导航栏

    上一章节,我们分享了如何创建一个新的页面和设置页面的标题,这一章我们来聊聊底部导航栏是如何实现的.即点击底部的导航,会实现不同对应页面之间的切换. 我们先来看个我们要实现的底部导航栏的效果图:(三个导 ...

随机推荐

  1. Uncaught TypeError: form.attr is not a function 解决办法

    前端form表单提交时遇到个问题,一直报错如下 首先说结论:form是个js对象,不是jQuery对象,不能用jquery对象的方法. 代码是: $(document).ready(function( ...

  2. Spring:AOP

    摘要 本文内容为我在网上搜集Spring AOP资料的汇总.摘抄. AOP是一种编程思想,其对不同对象进行了横向的抽象,将不同对象的.和主流程无关的公共逻辑抽象出来以方便维护.AOP的实现基础为AOP ...

  3. Java虚拟机运行时数据区域及垃圾回收算法

    程序计数器 记录正在执行的虚拟机字节码指令的地址(如果正在执行的是本地方法则为空). Java 虚拟机栈 每个 Java 方法在执行的同时会创建一个栈帧用于存储局部变量表.操作数栈.动态链接.方法出口 ...

  4. vue(一)vue-cli安装

    第一步:我们首先要全局安装vue官方提供的脚手架工具:vue-cli $ npm install vue-cli -g 第二步:然后我们就可以创建自己的vue项目了, $ vue init webpa ...

  5. VS下.net开发常用扩展、配置

    Vue.js Pack Copy As Html HTML Tools Word Highlight With Margin 绿豆沙颜色:R:199  G:237  U:204

  6. JS-jquery对象和dom对象的属性操作区别

    <label class="">时间1</label> <label class="">时间2</label> ...

  7. iOS socket常用数据类型转换

    int -> data /** int -> data */ + (NSData *)intToData:(int)value { Byte byte[4] = {}; byte[0] = ...

  8. 解决在vscode中eslint在vue后缀文件中保存时无法自动格式化的问题

    在setting.json中加入如下内容 { "eslint.autoFixOnSave": true, "eslint.validate": [ " ...

  9. django xadmin查找当前用户所在组

    self.request.user:获取当前登录用户用户名 qs = Group.objects.get(user=self.request.user)获取当前登录用户所在组qs.name 获取当前登 ...

  10. Node.js前端程序通过Nginx部署后刷新出现404问题的解决办法

    方案一 (这种方式容易被第三方劫持) location / { root /data/nginx/html; index index.html index.htm; error_page 404 /i ...