佳宸学习和分享笔记的地方

0%

vue.js商城项目(九)tabbar

vue.js商城项目(九)tabbar

取消路由中的#号

在new Router()的下一行添加上:mode: ‘history’,

使用vant tabBar组件

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
<template>
<div>
<van-tabbar
v-model="active"
>
<van-tabbar-item icon="shop" to='/'>首页</van-tabbar-item>
<van-tabbar-item icon="records" to='/CategoryList'>分类</van-tabbar-item>
<van-tabbar-item icon="cart" to='/Cart'>购物车</van-tabbar-item>
<van-tabbar-item icon="contact" to='User'>我的</van-tabbar-item>
</van-tabbar>
</div>
</template>

<script>
export default {
name:'Tab',
data() {
return {
active: 0,
}
},
watch: {
$route(to, from) {
console.log(to)
switch (to.fullPath) {
case '/':
this.active = 0;
break;
case '/CategoryList':
this.active = 1;
break;
case '/Cart':
this.active = 2;
break;
case '/User':
this.active = 3;
break;
default:
this.active = 0;
}
}
}
}
</script>

在App.vue中写入组件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<template>
<div id="app">
<keep-alive>
<router-view/>
</keep-alive>
<Tab v-show="!$route.meta.fullScreen" />
</div>
</template>

<script>
import Tab from '@/components/pages/Tab'
export default {
name: 'App',
components:{
Tab
}
}
</script>

在router中如果不是首级,设置全屏

1
2
3
meta: {
fullScreen: true
}

main.js中就可以做出判断