iKcamp|WeChat applet|Tools installation + directory description|Based on the latest version 1.0 developer tools junior tutorial share
On the page shown in step 8 of the previous section, you can click Developer Tools Go directly to the download page, or you can visit the official download address directly. Then select the appropriate download according to your device The installation process is not repeated and defaults all the way through.
Download Development Tools
The tools selected for this tutorial are for the mac platform version, no difference
Once the project is generated, you will see a directory file with the following structure.
├─ pages/ │ ├─ index/ │ ├─ index.js │ ├─ index.wxml │ ├─ index.wxss │ ├─ logs/ │ ├─ logs.js │ ├─ logs.json │ ├─ logs.wxml │ ├─ logs.wxss ├── utils/ │ ├─ util.js ├── app.js // Required Documents ├── app.json // Required Documents ├── app.wxss
app.json The file configures the two pages of the current applet pages/index/index harmony pages/logs/logs , as you can see, is actually Path + filename of the file Ingredients. If you add a page, you need to add a page to the parameter pages The address of the page is configured in the
Careful students may have noticed a phenomenon, each page folder, with the files inside, have the same name drops. Yes, in general, a complete page requires js 、wxss(css)、wxml(html) Ingredients. for example index page, if you need to make a change to the index page for some standalone configuration that requires something like logs Same, increase index.json file to save the configuration information.
<!--index.wxml--> <view class="container"> <view class="userinfo"> <button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> Get avatar nickname </button> <block wx:else> <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image> <text class="userinfo-nickname">{{userInfo.nickName}}</text> </block> </view> <view class="usermotto"> <text class="user-motto">{{motto}}</text> </view> </view>
traditional html The file consists of a variety of tags, and the wxml in which there are not many tag elements available, it can be seen that there are view、image、text Tags.
There are also some good built-in component tags, Self-styled harmony characteristics, for further details, refer to Official Documents
The scope only takes effect on the current page, and it can override the app.wxss Inside the style rules. As you can see, there is basically no difference from the usual style files we use: the
/**index.wxss**/ .userinfo { display: flex; flex-direction: column; align-items: center; } .userinfo-avatar { width: 128rpx; height: 128rpx; margin: 20rpx; border-radius: 50%; } .userinfo-nickname { color: #aaa; } .usermotto { margin-top: 200px; }
with app.js Same, contains the lifecycle of a page, declares and processes data, responds to page interaction events, etc.
//index.js // Get application examples const app = getApp() Page({ data: { motto: 'Hello World', userInfo: {}, hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo') }, // Event handling functions bindViewTap: function() { wx.navigateTo({ url: '../logs/logs' }) }, onLoad: function () { if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, hasUserInfo: true }) } else if (this.data.canIUse){ // Since getUserInfo is a network request, it may not be returned until after Page.onLoad // So callback is added here to prevent this app.userInfoReadyCallback = res => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } } else { // Compatible handling in the absence of the open-type=getUserInfo version wx.getUserInfo({ success: res => { app.globalData.userInfo = res.userInfo this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) } }, getUserInfo: function(e) { console.log(e) app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) } })
Next update: Beginner's tutorial for small programs - lit. try a small test drive+ Release Process