


This article mainly introduces the relevant information about the detailed introduction of the view layer (xx.xml) and logic layer (xx.js) of the WeChat applet. Friends in need can refer to it
WeChat applet can understand For the concept of cloud OS, the WeChat ecosystem itself is an OS. In addition, the WeChat public platform and the WeChat development platform themselves are already very mature structures, which can perfectly match the functions of Apps. At the same time, they can also achieve the ultimate in interactive experience, and have the potential to replace Apps. The significance of the Apple App Store model is to provide third-party software providers with a convenient and efficient software sales platform. The fees paid by users to purchase apps are split 3:7 between Apple and app developers. If the WeChat mini program mall also adopts a similar commission model, the more than 800 million users will be a very large intangible asset and become another source of gold for Tencent after games, memberships, and advertising.
WeChat mini programs allow people to use apps without downloading and installing them. Users can scan the QR code on WeChat to open the program. WeChat applet can be applied on different systems such as Android and iOS, and can also be shared on different platforms, because it itself is similar to a website page.
Mini program view layer (xx.xml) and logic layer (xx.js)
The entire system is divided into two parts The view layer (View) and logic layer (App Service)
framework allows data and views to be synchronized very simply. When modifying data, you only need to modify the data in the logical layer, and the view layer will update accordingly.
Look at this simple example:
<!-- This is our View --> <view> Hello {{name}}! </view> <button bindtap="changeName"> Click me! </button> // This is our App Service. // This is our data. var helloData = { name: 'WeChat' } // Register a Page. Page({ data: helloData, changeName: function(e) { // sent data change to view this.setData({ name: 'MINA' }) } })
The developer binds the name in the logic layer data to the name in the view layer through the framework, so in When the page is opened, it will display Hello WeChat!
-
When the button is clicked, the view layer will send the changeName event to the logic layer, and the logic layer will find the corresponding event processing function
The logic layer performed the setData operation and changed the name from WeChat to MINA. Because the data has been bound to the view layer, the view layer will automatically change to Hello MINA!.
The view layer is xx.xml
The logic layer is xx.js
Read It will first look at the initial data of the logic layer to populate the view layer. The view layer triggers events in the logic layer, and the logic layer returns and changes the content of the view layer.
Logic layer (App Service)
The logic layer of the small program development framework is written by JavaScript.
The logic layer processes the data and sends it to the view layer, and at the same time accepts event feedback from the view layer. Based on JavaScript, we made some modifications to facilitate the development of small programs.
Add App and Page methods to register programs and pages.
Provides rich API, such as scanning, payment and other WeChat-specific capabilities.
Each page has an independent scope and provides modular capabilities.
Since the framework does not run in the browser, some JavaScript capabilities cannot be used in the web, such as document, window, etc.
All the code written by the developer will eventually be packaged into a JavaScript and run when the mini program starts until the mini program is destroyed. Similar to ServiceWorker, so the logic layer is also called App Service.
Initialization data
Initialization data will be used as the first rendering of the page. The data will be transmitted from the logic layer to the rendering layer in the form of JSON, so the data must be in a format that can be converted into JSON: strings, numbers, Boolean values, objects, and arrays.
The rendering layer can bind data through WXML.
Sample code:
<view>{{text}}</view> <view>{{array[0].msg}}</view> Page({ data: { text: 'init data', array: [{msg: '1'}, {msg: '2'}] } })
Page.prototype.setData()
Note:
1. Directly modifying this.data is invalid and cannot change thestatus of the page. It will also cause data inconsistency. 2. The data set at a time cannot exceed 1024kB. Please try to avoid setting too much data at one time.
setData() parameter format
key, value, represents changing the value corresponding to the key in this.data to value.
The key can be very flexible and given in the form of a data path, such as array[2].message, a.b.c.d, and does not need to be predefined in this.data. Sample code:<!--index.wxml--> <view>{{text}}</view> <button bindtap="changeText"> Change normal data </button> <view>{{array[0].text}}</view> <button bindtap="changeItemInArray"> Change Array data </button> <view>{{obj.text}}</view> <button bindtap="changeItemInObject"> Change Object data </button> <view>{{newField.text}}</view> <button bindtap="addNewField"> Add new data </button> //index.js Page({ data: { text: 'init data', array: [{text: 'init data'}], object: { text: 'init data' } }, changeText: function() { // this.data.text = 'changed data' // bad, it can not work this.setData({ text: 'changed data' }) }, changeItemInArray: function() { // you can use this way to modify a danamic data path this.setData({ 'array[0].text':'changed data' }) }, changeItemInObject: function(){ this.setData({ 'object.text': 'changed data' }); }, addNewField: function() { this.setData({ 'newField.text': 'new data' }) } })
View layer
WXSS, written by components for display.
将逻辑层的数据反应成视图,同时将视图层的事件发送给逻辑层。
WXML(WeiXin Markup language)用于描述页面的结构。
WXSS(WeiXin Style Sheet)用于描述页面的样式。
组件(Component)是视图的基本组成单元。
什么是事件
事件是视图层到逻辑层的通讯方式。
事件可以将用户的行为反馈到逻辑层进行处理。
事件可以绑定在组件上,当达到触发事件,就会执行逻辑层中对应的事件处理函数。
事件对象可以携带额外信息,如id, dataset, touches。
事件的使用方式
在组件中绑定一个事件处理函数。
如bindtap,当用户点击该组件的时候会在该页面对应的Page中找到相应的事件处理函数。
<view id="tapTest" data-hi="MINA" bindtap="tapName"> Click me! </view> 在相应的Page定义中写上相应的事件处理函数,参数是event。 Page({ tapName: function(event) { console.log(event) } })
基础组件
框架为开发者提供了一系列基础组件,开发者可以通过组合这些基础组件进行快速开发。
什么是组件:
组件是视图层的基本组成单元。
组件自带一些功能与微信风格的样式。
一个组件通常包括开始标签和结束标签,属性用来修饰这个组件,内容在两个标签之内。
<tagname property="value"> Content goes here ... </tagename>
注意:所有组件与属性都是小写,以连字符-连接
【相关推荐】
1. 微信小程序之页面传值详解
The above is the detailed content of Detailed explanation of the view layer (xx.xml) and logic layer (xx.js) in WeChat development. For more information, please follow other related articles on the PHP Chinese website!

PHP是一种开源的脚本语言,广泛应用于Web开发和服务器端编程,尤其在微信开发中得到了广泛的应用。如今,越来越多的企业和开发者开始使用PHP进行微信开发,因为它成为了一款真正的易学易用的开发语言。在微信开发中,消息的加密和解密是一个非常重要的问题,因为它们涉及到数据的安全性。对于没有加密和解密方式的消息,黑客可以轻松获取到其中的数据,对用户造成威胁

微信是目前全球用户规模最大的社交平台之一,随着移动互联网的普及,越来越多的企业开始意识到微信营销的重要性。在进行微信营销时,客服服务是至关重要的一环。为了更好地管理客服聊天窗口,我们可以借助PHP语言进行微信开发。一、PHP微信开发简介PHP是一种开源的服务器端脚本语言,广泛运用于Web开发领域。结合微信公众平台提供的开发接口,我们可以使用PHP语言进行微信

在微信公众号开发中,用户标签管理是一个非常重要的功能,可以让开发者更好地了解和管理自己的用户。本篇文章将介绍如何使用PHP实现微信用户标签管理功能。一、获取微信用户openid在使用微信用户标签管理功能之前,我们首先需要获取用户的openid。在微信公众号开发中,通过用户授权的方式获取openid是比较常见的做法。在用户授权完成后,我们可以通过以下代码获取用

随着微信的普及,越来越多的企业开始将其作为营销工具。而微信群发功能,则是企业进行微信营销的重要手段之一。但是,如果只依靠手动发送,对于营销人员来说是一件极为费时费力的工作。所以,开发一款微信群发工具就显得尤为重要。本文将介绍如何使用PHP开发微信群发工具。一、准备工作开发微信群发工具,我们需要掌握以下几个技术点:PHP基础知识微信公众平台开发开发工具:Sub

随着互联网和移动智能设备的发展,微信成为了社交和营销领域不可或缺的一部分。在这个越来越数字化的时代,如何使用PHP进行微信开发已经成为了很多开发者的关注点。本文主要介绍如何使用PHP进行微信开发的相关知识点,以及其中的一些技巧和注意事项。一、开发环境准备在进行微信开发之前,首先需要准备好相应的开发环境。具体来说,需要安装PHP的运行环境,以及微信公众平台提

随着微信成为了人们生活中越来越重要的一个通讯工具,其敏捷的消息传递功能迅速受到广大企业和个人的青睐。对于企业而言,将微信发展为一个营销平台已经成为趋势,而微信开发的重要性也逐渐凸显。在其中,群发功能更是被广泛使用,那么,作为PHP程序员,如何实现群发消息发送记录呢?下面将为大家简单介绍一下。1.了解微信公众号相关开发知识在了解如何实现群发消息发送记录之前,我

ThinkPHP6微信开发指南:快速搭建微信公众号应用引言:微信公众号作为一种重要的社交媒体平台,为个人和企业在市场推广、信息传播等方面提供了很大的机会。在这篇文章中,我们将介绍如何使用ThinkPHP6快速搭建一个微信公众号应用,并且提供一些常用的代码示例。环境准备在开始开发之前,我们首先需要准备好以下环境:PHP7以上版本ThinkPHP6框架微信公众号

随着移动互联网的普及,微信作为一款社交软件,越来越多的人开始使用,并且微信开放平台也给开发者带来了众多的机会。近年来,随着人工智能技术的发展,语音识别技术逐渐成为了移动端开发的热门技术之一。在微信开发中,如何实现语音识别成为很多开发者关注的问题。本文将介绍如何利用PHP开发微信应用实现语音识别功能。一、语音识别原理在介绍如何实现语音识别之前,我们先了解一下语


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
