Home  >  Article  >  WeChat Applet  >  What do you need to pay attention to when using mini programs?

What do you need to pay attention to when using mini programs?

小云云
小云云Original
2018-03-17 14:37:551539browse

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.

#a8899951655249ad0ef4f91602aa4354
# (2).

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

1075a5d2afd5223d26c7e913f8374360 click me de5f4c1163741e920c998275338d29b2



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

51184bddf12d7f17d51841733bd1d942List 1de5f4c1163741e920c998275338d29b2

##

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

283eed59fef83674640c93d96f3ff046{{firstPerson}}de5f4c1163741e920c998275338d29b2

##be3f48542c77193a123ead93bc479888eatde5f4c1163741e920c998275338d29b2

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

c89ae9cf7ee98599514ae4f90566f40ff8e950ebc6c1ea27f76cf997b9216fe6


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