需要添加的tabbar有三个页面,分别为首页、课程页、我的。如下图所示:
新建文件
src/pages/index/index.vue
src/pages/course/index.vue
src/pages/user/index.vue
Tips: 注意文件命名与uni-app关键字不要冲突,不然可能会报错,然后你还找不到错误是啥
文件内容:
<template>
<view class="content"> 首页 </view>
</template>
<script>
export default {
data() {
return {
title: "Hello",
};
},
onLoad() {},
methods: {},
};
</script>
<style>
</style>
现在需要把页面添加到page.json
中去
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "谷粒微课"
}
},
{
"path": "pages/course/index",
"style": {
"navigationBarTitleText": "谷粒微课"
}
},
{
"path": "pages/user/index",
"style": {
"navigationBarTitleText": "谷粒微课"
}
}
],
配置tabbar
,也是在page.json
中配置,更多配置参数参考配置项列表。
"tabBar": {
"backgroundColor": "#17181a",
"selectedColor": "#409EFF",
"color": "#a1a7b2",
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "static/images/nav/home-off.png",
"selectedIconPath": "static/images/nav/home-on.png",
"text": "首页"
},
{
"pagePath": "pages/course/index",
"iconPath": "static/images/nav/list-off.png",
"selectedIconPath": "static/images/nav/list-on.png",
"text": "课程"
},
{
"pagePath": "pages/user/index",
"iconPath": "static/images/nav/my-off.png",
"selectedIconPath": "static/images/nav/my-on.png",
"text": "我的"
}
]
},
现在我们在页面中看到的就是开始那个页面。