uni-app是一个使用Vue.js开发所有前端应用的框架,开发者编写一套代码,可发布到iOS、Android、H5、以及各种小程序(微信/支付宝/百度/头条/QQ/钉钉/淘宝)、快应用等多个平台。
uni-app是由dcloud公司开发的,多端融合框架,一次开发,多端运行,它的竞品:apiCloud,appCan,Codova,技术架构:vue的语法+小程序的api
uni-app的使用遵循vue的基本语法,这里简单回顾一下
<view>
<view class="title">文本渲染view>
<view>{{title}}view>
<view v-text="title">view>
<view>{{2+3}}view>
<view>{{title.length}}view>
<view>{{title.split("").reverse().join("")}}view>
<view>{{title.length>10?"是的":"并不是"}}view>
<view v-html="str">view>
view>
<view>
<view class="title">条件渲染view>
<view v-if="isLog">欢迎您,亲爱的xxxview>
<view v-else>请先登录view>
<view v-show="isLog">欢迎欢迎view>
<view v-show="!isLog">请先登录view>
<view v-if="score>90">奖励一辆小汽车view>
<view v-else-if="score>80">奖励一台电脑view>
<view v-else-if="score>70">奖励一辆电瓶车view>
<view v-else-if="score>60">奖励一辆滑板车view>
<view v-else>打一顿view>
view>
<view>
<view class="title">列表渲染view>
<view>-----遍历列表-----view>
<view v-for="(item,index) in list" :key="index+1">{{item}}view>
<view>-----遍历对象-----view>
<view v-for="(value,key) in obj" v-bind:key="key">{{value}}view>
<view>-----遍历数字-----view>
<view v-for="item in 5">{{item}}view>
<view>-----遍历字符串-----view>
<view v-for="(s,i) in title" :key="i+2">{{s}}view>
view>
<view>
<view class="title">属性渲染view>
<button type="primary" :disabled="isLog" @click="isLog=!isLog">按钮button>
<button type="warn" :disabled="!isLog" @click="isLog=!isLog">按钮button>
view>
<view>
<view class="title">表单绑定view>
<view>{{title}}---{{time}}---{{num}}view>
<view>-----选择-----view>
<picker mode="time" :value="time" start="09:01" end="21:01" @change="time=$event.detail.value">
<view class="uni-input">{{time}}view>
picker>
<view>-----输入-----view>
<input type="text" placeholder="请输入..." :value="title" v-model="title">
<view>-----滑块-----view>
<slider :value="num" @change="num=$event.detail.value" step="5" />
view>
<view>
<view class="title">事件绑定view>
<button v-on:click="num++" type="primary" size="mini">{{num}}绑定事件button>
<button @click="num++" type="warn" size="mini">{{num}}绑定事件-简写button>
<button @click="say()" type="primary" size="mini">响应函数button>
<button @click="say('你好,亲爱的祖国')" type="warn" size="mini">响应函数-传参button>
<button @click="doit" type="primary" size="mini" :data-title="title">事件对象button>
view>
export default {
data() {
return {
time:"12:01",
title: '你好,我是uni-app',
num:1,
str:"祖国繁荣昌盛,那是必须的",
isLog:true,
score:85,
list:["vue","react","angular","jquery"],
obj:{"小王":"javascript","小李":"html5","小赵":"css3"},
}
},
onLoad() {
},
methods: {
say(str="你好"){
uni.showToast({//提示
title:str
})
},
doit(e){
console.log(e);
uni.showModal({//弹框
title:e.target.dataset.title
})
}
}
}
(同等级会优先执行小程序的生命周期,再执行vue的生命周期)
网址:https://uniapp.dcloud.net.cn/tutorial/page.html
< navigator> navigator>
"tabBar": {
"color": "#999",
"selectedColor": "#FF7984",
// "midButton": {
// "text": "123",
// "iconPath": "static/logo.png"
// },
"list":[
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "static/sy.png",
"selectedIconPath": "static/sy1.png"
},
{
"pagePath": "pages/life/life",
"text": "生命",
"iconPath": "static/hs.png",
"selectedIconPath": "static/hs1.png"
},
{
"pagePath": "pages/options/options",
"text": "选项",
"iconPath": "static/kt.png",
"selectedIconPath": "static/kt1.png"
},
{
"pagePath": "pages/condition/condition",
"text": "条件",
"iconPath": "static/wd.png",
"selectedIconPath": "static/wd1.png"
}
]
}
<view>条件编译view>
<view>H5:下载APP获取优惠券view>
<view>wx:小程序优惠券50元view>
<view>app:app优惠券5元view>
< view class=“active”>我是奇奇怪怪的一行文字 view>
<view class="active">我是奇奇怪怪的一行文字view>
<button @click="say()">你好button>
say(){
// #ifdef APP
uni.showModal({
title:"你好App用户"
})
// #endif
// #ifdef H5
uni.showModal({
title:"你好手机用户"
})
// #endif
// #ifdef MP
uni.showToast({
title:"你好微信用户"
})
// #endif
}
"style" :
{
"navigationBarTitleText": "条件编译",
"enablePullDownRefresh": false,
"h5": {
"titleNView": {
"titleText": "我是H5"
}
},
"app-plus": {
// "titleNView": false
"titleNView": {
"titleText": "我是APP"
}
}
}