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