以前我胖汾公司年會、問我能不能幫忙搞個小程序方便他們進行遊戲後的懲罰/抽獎使用、出了個簡單的設計圖、大概三天左右作了個簡單的小程序、目前提交審覈了。對於寫過一小段時間vue來講小程序很容易上手、寫法和結構差很少。php
-----------------css
這裏整理的內容大體劃分四個部分html
①常規選型vue
②靜態頁面git
③接入Bmob數據庫github
④發佈小程序數據庫
⑤我的開發過程的筆記。json
------------------小程序
小程序-萌小福團建(密鑰:20190101)後端
靜態完整代碼:https://github.com/GugaLiz/GamePunishment/tree/master
接入Bmob數據庫後的完整代碼:https://github.com/GugaLiz/GamePunishment/tree/br/2.x
①簡易教程(第一次開發小程序請務必看完簡易教程這一頁好嗎?答應我!主要是看看怎麼申請小程序和安裝上開發工具,有公衆號的注意,登陸頁面跟公衆號是同樣的,根據你的登陸帳戶區分登陸公衆號仍是小程序的!!!):https://developers.weixin.qq.com/miniprogram/dev/
②組件:https://developers.weixin.qq.com/miniprogram/dev/component/
③API:https://developers.weixin.qq.com/miniprogram/dev/api/
①樣式瀏覽:https://weui.io/
②對應樣式的源碼:https://github.com/Tencent/weui-wxss
①如何在小程序中使用文檔:http://doc.bmob.cn/data/wechat_app_new/index.html
②Bmob後端雲(登陸進去就能夠建項目的數據庫了):https://www.bmob.cn/
③Bmob使用實例:https://www.jianshu.com/p/4894bd07fa31
①到官網https://github.com/Tencent/weui-wxss把weui項目clone到本地。
②解壓縮-進入weui-wxss-master\dist\style文件夾-找到weui-wxss-master\dist\style\weui.wxss文件
③把weui.wxss文件複製到你的小程序項目根目錄下面便可,開發工具上就能夠看到
④在項目中引用:在app.wxss中加入weui.wxss的引用 @import ‘weui.wxss’;
⑤在項目中使用便可(能夠打開https://weui.io/找到本身要的樣式,對應https://github.com/Tencent/weui-wxss這裏能夠找到參考代碼)
好比:我要使用button在https://weui.io/#button看我要哪一種,而後我去https://github.com/Tencent/weui-wxss/tree/master/src/example/button這裏就查看到代碼咯。ctrl +C -- ctril+V曉得了吧。
②iconfont使用手冊
搜圖標
-添加入庫
-點擊右上角的購物車-添加至項目
-點擊下載到本地
③將下載的download解壓縮-找到 iconfont.css 文件,將裏面的內容所有複製到小程序的app.wxss裏面
!注意:若是你又在iconfont裏面添加了新的圖標、是要更改這個文件的!!
首先是在你的項目裏面查看代碼,會提示你新增了圖標要刷新看代碼了
把這段代碼複製到app.wxss中,位置就是@font-face{..}這段,同時下面要添加你的圖標定義。
④使用iconfont
個人靜態的代碼在這裏,能夠參考借鑑(順手求個start感謝):https://github.com/GugaLiz/GamePunishment/tree/master
參考資料走一波:http://docs.bmob.cn/data/wechatApp/a_faststart/doc/index.html#註冊Bmob賬號
個人使用案例:
①引入Bmob.js到小程序項目
②在要用Bmob的頁面聲明及使用
好比在個人redPackagesDetail.js
聲明:
// pages/redPackagesDetail/redPackagesDetail.js var Bmob = require("../../utils/dist/Bmob-1.6.7.min.js"); var query = Bmob.Query("result"); Page({ /** * 頁面的初始數據 */ data: { details:[] }, /** * 生命週期函數--監聽頁面加載 */ onLoad: function (options) { var me = this; if(options.userName){ query.equalTo("userName", "==", options.userName); query.find().then(res => { //res.map((item) => (item.updatedAt = (item.updatedAt.split(' ')[1]))); me.setData({ details: res }) }); } }, /** * 生命週期函數--監聽頁面初次渲染完成 */ onReady: function () { }, /** * 生命週期函數--監聽頁面顯示 */ onShow: function () { }, /** * 生命週期函數--監聽頁面隱藏 */ onHide: function () { }, /** * 生命週期函數--監聽頁面卸載 */ onUnload: function () { }, /** * 頁面相關事件處理函數--監聽用戶下拉動做 */ onPullDownRefresh: function () { }, /** * 頁面上拉觸底事件的處理函數 */ onReachBottom: function () { }, /** * 用戶點擊右上角分享 */ onShareAppMessage: function () { } })
接入Bmob之後的小程序徹底代碼在這裏(求個順手start):https://github.com/GugaLiz/GamePunishment/tree/br/2.x
小程序開發工具-右上角「上傳」
①設置你的小程序信息
小程序頁面-設置-基本設置
②提交審覈(要填你的功能頁面信息,儘可能把大頁面的填好填滿,否則會打回從新審覈)
小程序頁面-管理-版本管理-審覈版本
③若是有打回,按照他反饋信息進行修改,再提交審覈便可。
在app.json文件中添加代碼
1 { 2 "pages": [ 3 "pages/index/index", 4 "pages/logs/logs", 5 "pages/setting", 6 "pages/setting/setting" 7 ], 8 "window": { 9 "backgroundTextStyle": "light", 10 "navigationBarBackgroundColor": "#fff", 11 "navigationBarTitleText": "WeChat", 12 "navigationBarTextStyle": "black" 13 }, 14 "tabBar": { 15 "color": "#dddddd", 16 "selectedColor": "#13227a", 17 "borderStyle": "white", 18 "list": [ 19 { 20 "pagePath": "pages/index/index", 21 "iconPath": "images/index.png", 22 "selectedIconPath": "images/indexSel.png", 23 "text": "首頁" 24 }, 25 { 26 "pagePath": "pages/setting/setting", 27 "iconPath": "images/setting.png", 28 "selectedIconPath": "images/settingSel.png", 29 "text": "設置" 30 } 31 ] 32 } 33 }
頁面 index.wxml <button class="weui-btn" type="default" plain="true" bindtap="packageEnter">抽獎</button> 頁面 index.js packageEnter:function(){ wx.navigateTo({ url: '../redPackage/redPackage' }) },
方式二:在.wxml文件中直接寫跟html的<a></a>標籤相似
<view class="setting"> <navigator url='../redPackagesSetting/redPackagesSetting'> <text class='iconfont icon-shezhi' style="color:#FFB1B0;font-size:25px;" > </text> </navigator> </view>
方式三:帶參數跳轉頁面 <navigator url="../redPackagesDetail/redPackagesDetail?userName={{item.userName}}">GugaLiz</navigator >
參考資料:https://www.cnblogs.com/azhqiang/p/9634334.html
wxml頁面
<view wx:for="{{counts}}" wx:key="index"> <navigator url="../redPackagesDetail/redPackagesDetail?userName={{item.userName}}"> <view class="weui-cells weui-cells_after-title"> <view class="weui-cell weui-cell_access"> <view class="weui-cell__bd"> <view style="display: inline-block; vertical-align: middle;width:50%;">{{item.userName}}</view> <view class="weui-badge" style="margin-left: 5px;">共{{item._sumMoney}}元</view> </view> <view class="weui-cell__ft weui-cell__ft_in-access" style="font-size: 0" > <view style="display: inline-block;vertical-align:middle; font-size: 17px;" >詳細</view> <view class="weui-badge weui-badge_dot" style="margin-left: 5px;margin-right: 5px;" ></view> </view> </view> </view> </navigator> </view>
js頁面
Page({ /** * 頁面的初始數據 */ data: { counts:[{userName:"GugaLiz",_sumMoney:2},{userName:"Echo",_sumMoney:12}] }, /** * 生命週期函數--監聽頁面加載 */ onLoad: function (options) { console.log(options.userName); //輸出url帶過來的參數 }, })
其它(參考官方文檔的API):https://developers.weixin.qq.com/miniprogram/dev/api/wx.navigateBack.html
參考資料
(三種彈框寫法) http://www.php.cn/xiaochengxu-388964.html
(獲取input的值) https://www.cnblogs.com/dashucoding/p/10008119.html
(清空input) https://blog.csdn.net/huangmeimao/article/details/74936966