当前位置:   article > 正文

【uni-app 自定义底部导航可页面跳转】_uniapp 点击底部导航打开外部链接

uniapp 点击底部导航打开外部链接

uni-app 自定义底部导航可页面跳转

效果图:
在这里插入图片描述

1.写好模板放数据内容,这个自定义底部我是按照组件格式去写的,如何写组件和使用组件,直接放在页面上也能用
<template>
	<view>
		<view class="bot_nav" style="position: relative;">

		</view>
		<view class="bot_nav " style="position: fixed;">
			<view class="fle1 fle_all " :class="item.is_click?'cur':''" v-for="(item,index) in bot_nav" :key='index' @tap="bot_nav_click(index)">
				<view class="fle fle_col">
					<view class="fle_sta fle_all wth100">
						<view class="img">
							<image :src="item.img_click_src" mode="" v-if="index == bot_cli"></image>
							<image :src="item.img_src" mode="" v-if="index != bot_cli"></image>
						</view>
					</view>
					<view class="fle_end wth100 fle_all">
						<text>{{item.name}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
2.初始化数据

博主的基本样式复制处)

初始化底部图片(图片放在static里),底部字样,选中后的图片,跳转链接

		props:{
			bot_cli:{
				type:Number,
				default:0
			}
		},
		data() {
			return {
				bot_nav: [{
					img_src: "../../../static/01.png",
					name: "首页",
					img_click_src: "../../../static/02.png",
					src:"../../tabBar/homePage/homePage"
				}, {
					img_src: "../../../static/01.png",
					name: "分类",
					img_click_src: "../../../static/02.png",
					src:"../../tabBar/function/function"
				}, {
					img_src: "../../../static/01.png",
					name: "商城",
					img_click_src: "../../../static/04.png",
					src:"../../tabBar/personal/personal"
				}, {
					img_src: "../../../static/01.png",
					name: "个人中心",
					img_click_src: "../../../static/05.png",
					src:"../../tabBar/homePage/homePage"
				}],
				
			}
		},


//样式
	.bot_nav{
		border-top: 1rpx solid #eee;
		position: absolute;
		bottom: 0%;
		height: 120rpx;
		width: 100%;
		color: #999;
		background-color: white;
		display: flex;
		z-index: 99;
	}
	.bot_nav .img{
		width: 40rpx;
		height: 40rpx;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		background-color: #ccc;
	}
	.bot_nav .cur{
		color: #333;
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
3.写方法

点击方法保存全局数据(点击了哪一个),跳转至相应的tabbra页面的链接

		methods: {
			bot_nav_click(e) {
				uni.redirectTo({
				    url: this.bot_nav[e].src
				});

			}
			
		}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
4.main.js全局引用这个底部组件

如果是直接放在页面上就不需要以下步骤

import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

import comeBack from './pages/component/come-back/come-back.vue'//挂载
Vue.component('comeBack',comeBack) //挂载
import botton from './pages/component/botton/botton.vue'//挂载
Vue.component('botton',botton) //挂载

App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
5.页面直接写标签名就可以使用

需要改里面的字样或者图片在组件里改就可以了,给组件一个提示当前是那个页面已点击

<template>
	<view>
		<botton bot_cli="0"></botton>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			
		}
	}
</script>

<style>

</style>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

让我看看有谁还没有点赞
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/131594
推荐阅读