1.在HBuilderX中新建uni-app
![](https://img.haomeiwen.com/i3388039/d66bfb8f2c347b98.jpg)
2.项目初始目录结构
![](https://img.haomeiwen.com/i3388039/f5cf12198a96e9a8.png)
3.调整项目目录结构如下图
![](https://img.haomeiwen.com/i3388039/02b0daa6cbbedeb7.png)
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.启动雷神模拟器,选择真机运行
![](https://img.haomeiwen.com/i3388039/6d0cb5d3d1ca1bb0.png)
控制台信息:
![](https://img.haomeiwen.com/i3388039/35fc68f20b8caa55.png)
模拟器运行效果
![](https://img.haomeiwen.com/i3388039/004ff8e2d77fd526.png)
![](https://img.haomeiwen.com/i3388039/37e956f29feb98ea.jpg)
点击“设置”可以跳转到个人设置新页面,也可以返回到“我的”页面
![](https://img.haomeiwen.com/i3388039/13ac7d4bd0b3c814.jpg)
7.真机插入USB也可以运行
8.uni-app官网:https://uniapp.dcloud.io/
9.阿里巴巴矢量图标库:https://www.iconfont.cn/
网友评论