1、初步认识javascript
npm install -g @vue/cli vue create -p dcloudio/uni-preset-vue my-project //运行并发布微信小程序版uni-app npm run dev:mp-weixin npm run build:mp-weixin
2、框架简介css
3、目录结构html
┌─components uni-app组件目录 │ └─comp-a.vue 可复用的a组件 ├─hybrid 存放本地网页的目录,详见 ├─platforms 存放各平台专用页面的目录,详见 ├─pages 业务页面文件存放的目录 │ ├─index │ │ └─index.vue index页面 │ └─list │ └─list.vue list页面 ├─static 存放应用引用静态资源(如图片、视频等)的目录,注意:静态资源只能存放于此 ├─wxcomponents 存放小程序组件的目录,详见 ├─main.js Vue初始化入口文件 ├─App.vue 应用配置,用来配置App全局样式以及监听 应用生命周期 ├─manifest.json 配置应用名称、appid、logo、版本等打包信息,详见 └─pages.json 配置页面路由、导航条、选项卡等页面类信息,详见
注意: vue
4、生命周期java
5、路由es6
{ "pages": [ { "path": "pages/index/index", "style": { ... } }, { "path": "pages/login/login", "style": { ... } } ] }
<template> <view> <view class="page-body"> <view class="btn-area"> <navigator url="navigate/navigate?title=navigate" hover-class="navigator-hover"> <button type="default">跳转到新页面</button> </navigator> <navigator url="redirect/redirect?title=redirect" redirect hover-class="other-navigator-hover"> <button type="default">在当前页打开</button> </navigator> </view> </view> </view> </template>
uni.navigateTo(OBJECT): 保留当前页面,跳转到应用内的某个页面 // -----> uni.navigateBack: 返回原页面 uni.navigateTo({ url: 'test?id=1&name=uniapp' }); uni.redirectTo(OBJECT):关闭当前页面,跳转到应用内的某个页面 uni.reLaunch(OBJECT):关闭全部页面,打开到应用内的某个页面 uni.switchTab(OBJECT):跳转到tabBar页面,并关闭其余全部非tabBar页面 // -----> pages.json: { "tabBar": { "list": [{ "pagePath": "pages/index/index", "text": "首页" },{ "pagePath": "pages/other/other", "text": "其余" }] } } // ------> other.vue: uni.switchTab({ url: '/pages/index/index' }); uni.navigateBack(OBJECT):关闭当前页面,返回上一页面或多级页面。 可经过 getCurrentPages() 获取当前的页面栈,决定须要返回几层。
6、页面栈web
<script> export default { computed: { halfWidth() { return uni.upx2px(750 / 2) + 'px'; } } } </script>
<style> @import "../../common/uni.css"; </style>
<view :style="{color:color}" /> <view class="normal_view" />
page { background-color:#ccc; }
① 图片小于 40kb,uni-app 会自动将其转化为 base64 格式;
② 图片大于等于 40kb, 需开发者本身将其转换为base64格式使用,
或将其挪到服务器上,从网络地址引用。
③ 本地背景图片的引用路径仅支持以 ~@ 开头的绝对路径(不支持相对路径)vue-cli
<template> <view> <template v-if="test"> <view>test 为 true 时显示</view> </template> <template v-else> <view>test 为 false 时显示</view> </template> </view> </template>
<template> <view> <block v-for="(item,index) in list" :key="index"> <view>{{item}} - {{index}}</view> </block> </view> </template>
注:以上内容来自UniApp官网npm