概念
首先他是vue和小程序的结合,页面中的一些基本语法同vue,路由配置以及导航栏的颜色设置等都类似于小程序
创建页面:
1 新建项目-选择uniapp(使用hbuider开发版,uniapp官网可见) 2 新建页面-选择pages右击选择新建页面,路由便会在pages.json中自动生成 3 路由导航,类似小程序,页面中类似vue如下
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
<p>这是第二个uniapp项目</p>
<!-- 设置路由导航,声明式和编程式 -->
<navigator url="../home/home">去首页</navigator>
<button type="default" @click="fun">去首页</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
fun(){
console.log("你好世界"),
uni.navigateTo({
url:"../home/home",
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
pages.json中(路由以及顶、底部导航栏设置等)
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app"
}
}
,{
"path" : "pages/home/home",
"style" :
{
"navigationBarTitleText": "这是首页",
"enablePullDownRefresh": false
}
}
,{
"path" : "pages/clone/clone",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
}
}
|