1.在HBuilderX中新建uni-app
image
2.項目初始目錄結構
image
3.調整項目目錄結構如下圖
image
4.配置pages.json文件
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "主頁"
}
},
{
"path": "pages/ucenter/ucenter",
"style": {
"navigationBarTitleText": "我的"
}
},
{
"path": "pages/ucenter/setting",
"style": {
"navigationBarTitleText": "個人設置"
}
}
],
"tabBar": {
"color": "#000000",
"selectedColor": "#2F85FC",
"backgroundColor": "#FFFFFF",
"borderStyle": "black",
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "static/home.png",
"selectedIconPath": "static/home-active.png",
"text": "主頁"
},
{
"pagePath": "pages/ucenter/ucenter",
"iconPath": "static/center.png",
"selectedIconPath": "static/center-active.png",
"text": "我的"
}
]
},
"globalStyle": {
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#2F85FC",
"backgroundColor": "#FFFFFF"
}
}
5.簡單寫一下index.vue和ucenter.vue內容
index.vue
<template>
<view class="container ">
<text class="title">主頁,{{ title }}</text>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
};
},
onLoad() {},
methods: {}
};
</script>
<style>
.container {
width: 95%;
margin: 0 auto;
text-align: center;
}
.title {
font-size: 36upx;
color: #8f8f94;
}
</style>
ucenter.vue
<template>
<view class="container">
<text>{{ name }}的個人中心</text>
<navigator url="../ucenter/setting" hover-class="navigator-hover">
<button type="default">設置</button>
</navigator>
</view>
</template>
<script>
export default {
data() {
return {
name: '陶然然'
};
},
onLoad() {},
methods: {}
};
</script>
<style>
.container {
width: 95%;
margin: 0 auto;
text-align: center;
}
</style>
6.啟動雷神模擬器,選擇真機運行
image
控制臺信息:
image
模擬器運行效果
image
image
點擊“設置”可以跳轉到個人設置新頁面,也可以返回到“我的”頁面
image
7.真機插入USB也可以運行
8.uni-app官網:https://uniapp.dcloud.io/
9.阿里巴巴矢量圖標庫:https://www.iconfont.cn/