不知不觉后端搬砖六年了,回想过去,什么也没留下,忽然以为是时候写点什么了。html
为何我要选择小程序呢,主要是以为上手简单,易于传播,同时能够投放微信广告为本身赚零花钱,何乐而不为。个人第一个小程序主要是想总结下这几年的编程积累,同时分享出来。分为基础内容和实战篇,目前仅上线了基础内容。目前我已开发了一个小程序和一款基于LayaBox的小游戏。先把小程序的讲解完,而后会分享LayaBox开发的小游戏,目前小游戏在申请软著,申请后会所有分享出来给你们分享,请期待。前端
你们能够体验一下,请扫码:编程
闲话少聊,咱们开始正事。先把个人小程序运行效果图发一下。PS:(前端太烂,勿喷,欢迎高手不吝赐教)小程序
关于小程序文档结构的内容你们能够扫上边的二位码在小程序里查看或者去查看官方文档。后端
UI界面基于WEUI,目前处于学习阶段,欢迎你们加群交流,我会在评论区留言。微信
页面内容:网络
<view class="container"> <view class="userinfo"> <button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button> <block wx:else> <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image> <text class="userinfo-nickname">{{userInfo.nickName}}</text> </block> </view> <view class="usermotto"> <text class="user-motto"> 咱们坚持分享基于LayaBox开发的微信小游戏,并在这里讲解开发步骤,同时分享一些公共模块给你们!!! </text> </view> <view class="usermotto"> <text class="user-motto">Copyright © 2019</text> </view> <view> <text class="user-motto">{{motto}}</text> </view> </view>
这个首页的建立你们能够直接创一个快速启动项目,不须要过多修改。app
脚本文件函数
const app = getApp() Page({ data: { motto: ' 莹百游 All Rights Reserved.', userInfo: {}, hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo') }, //事件处理函数 bindViewTap: function() { wx.navigateTo({ url: '../logs/logs' }) }, onLoad: function () { if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, hasUserInfo: true }); wx.redirectTo({ url: '../home/home' }); } else if (this.data.canIUse){ // 因为 getUserInfo 是网络请求,可能会在 Page.onLoad 以后才返回 // 因此此处加入 callback 以防止这种状况 app.userInfoReadyCallback = res => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }); wx.redirectTo({ url: '../home/home' }); } } else { // 在没有 open-type=getUserInfo 版本的兼容处理 wx.getUserInfo({ success: res => { app.globalData.userInfo = res.userInfo this.setData({ userInfo: res.userInfo, hasUserInfo: true }) wx.redirectTo({ url: '../home/home' }); } }) } }, getUserInfo: function(e) { app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) wx.redirectTo({ url: '../home/home' }); } })
这段脚本咱们几乎不要修改什么内容,就能够实现用户受权获取用户头像和昵称,咱们只须要在里面实现跳转页面就行了。学习
本项目目前三个界面,我会分3篇讲解,但愿你们关注。所有代码我会在第三篇分享出来给你们,但愿你们加V群一块儿学习。
原文出处:https://www.cnblogs.com/wyang/p/10259572.html