Home  >  Article  >  WeChat Applet  >  A brief discussion on WeChat mini programs

A brief discussion on WeChat mini programs

高洛峰
高洛峰Original
2017-02-21 16:09:511519browse

In the raging development of Internet technology, various frameworks have emerged, and the WeChat applet should be the one that attracts the most attention at the moment. From news forums to QQ groups and WeChat groups, many friends who work in IT like to discuss and study this small program. Out of curiosity, I got involved.

The first step is to download the WeChat developer tools from the official website. It is divided into windows64, windows32 and mac. Select the corresponding one to download. Install after downloading, skip the steps.

Link: https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html?t=1475052055652

The second step is to download the demo.

Link: https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html?t=1475052055652

The third step is to open the WeChat developer tools , import the decompressed demo, so that you can happily experience the mini program.

In this process, we can know that the original small program is actually quite similar to many frameworks. Its page is no longer html, but like angular mode. The style suffix is ​​not css but wxss; the unit is no longer px but rpx.

Data binding is similar to angular.

The debugging interface is as follows:

A brief discussion on WeChat mini programs

Page code:

<view class="container">
  <view  bindtap="bindViewTap" class="userinfo">
    <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
    <text class="userinfo-nickname">{{userInfo.nickName}}</text>
  </view>
  <view class="usermotto">
    <text class="user-motto">{{motto}}</text>
  </view>
</view>

Style:

/**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;
}

js:

//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: &#39;Hello World&#39;,
    userInfo: {}
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: &#39;../logs/logs&#39;
    })
  },
  onLoad: function () {
    console.log(&#39;onLoad&#39;)
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }
})

Directory:

A brief discussion on WeChat mini programs

As you can see from app.json, the page is imported from here.

Look at app.js again, as shown below:

A brief discussion on WeChat mini programs

We can know the process of mini program page initialization, data acquisition and interface calling.

For more articles related to WeChat mini programs, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn