search
HomeWeChat AppletMini Program DevelopmentWhat do you need to pay attention to when using mini programs?

This article mainly shares with you what points you need to pay attention to in mini programs, hoping to help you better develop WeChat functions.

1. Details

1.A small program includes an app that describes the overall program and multiple Describe the page of each page

2. The applet framework is divided into the view layer and the logic layer

The logic layer is written in JavaScript.

The view layer is written by WXML and WXSS, and is displayed by components. Component is the basic component of the view.

##Reflect the data in the logical layer into a view, and at the same time Events from the view layer are sent to the logic layer.

## 2. Little knowledge points

1.App() function is used to register a small program. Accept one object parameter, which specifies the life cycle function of the applet, etc.

are all in the app.js file

2.Page() function is used to register a page. accept an object Parameters, which specify the initial data of the page, life cycle functions, event handling functions, etc.

##(1).Initialization data: data

data will be transmitted from the logic layer to the rendering layer in the form of JSON, so the data must be converted into JSON Format: string, number, boolean, object, array.

#What do you need to pay attention to when using mini programs?
# (2).

Life cycle function ## (3). Event handling function: bindtap

click me



#3.
Realize dynamic display and hiding of a certain control

List 1

##

data:{  
    open:false  
  },  
  showitem:function(){  
      this.setData({  
          open:!this.data.open  
      })  
  }
.display_show{  
    display: block;  
}  
.display_none{  
    display: none;  
}


##4.By data-* and e.target.dateset pass parameters

{{firstPerson}}

##eat

this.setData({  
             firstPerson:e.target.dataset.me,  
       })

At this time: firstPerson=eat


##5

.Flexible box word: display:flex;

##

<view class="phone_one" bindtap="clickPerson">  
    <view class="phone_personal">{{firstPerson}}</view>  
    <image src="../../image/i.png" class="personal_image {{selectArea ? &#39;rotateRight&#39; :&#39;&#39;}}"></image>  
</view>
In parent:

display: flex;

## justify-content:space-between;

##This way the subsets will be juxtaposed. justify-content:space-between;This way the subsets will be at both ends


6. Get your own style e.detail.width, e.detail.height



var app = getApp()
Page({
	data: {
		imgwidth:0,  
        imgheight:0,
        
	},
	imageLoad: function(e) {  
        var _this=this;  
        var $width=e.detail.width,    //获取图片真实宽度  
            $height=e.detail.height,  
            ratio=$width/$height;   //图片的真实宽高比例  
        var viewWidth=this.data.screenWidth,           //设置图片显示宽度,  
            viewHeight=parseInt(viewWidth/ratio);    //计算的高度值
        _this.setData({  
            imgwidth:viewWidth,  
            imgheight:viewHeight  
        })
    }


7.如何定义全局数据

在app.js的App({})中定义的数据或函数都是全局的,在页面中可以通过var app = getApp();  app.function/key的方式调用(不过我们没有必要再app.js中定义全局函数

(1)设置全局变量

App({

     globalData:{    
          userInfo:null,    
          test:"test"    
      }   

})

获取变量值

var test = getApp().globalData.test;    
console.log(test)   

三.注意点小程序误区

1.小程序不是Html5。小程序是微信全新定义的规范,是基于xml+js的,不支持也不兼容HTML,兼容受限的部分css写法。

小程序和腾讯X5引擎也没关系。X5是QQ浏览器团队的,是基于HTML的,但小程序是微信团队自研的

2.小程序不是b/s。微信宣传的一个重点,是触手可得,不用安装。但小程序并不是b/s的在线页面,它是c/s架构的。

3.小程序体验好并且小程序并非只适合低频或长尾应用

4. Mini program is not an app store, it is an OS (operating system)

Related recommendations:

WeChat applet global configuration development example

Development of WeChat mini-program tab function

Development of WeChat mini-program to upload pictures Example sharing

The above is the detailed content of What do you need to pay attention to when using mini programs?. For more information, please follow other related articles on 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

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function