search
HomeWeChat AppletMini Program DevelopmentA brief discussion on WeChat mini programs

A brief discussion on WeChat mini programs

Feb 21, 2017 pm 04:09 PM
WeChat applet

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),