


Detailed explanation of the steps for developing small programs in mpvue
This time I will bring you a detailed explanation of the steps to develop a small program with mpvue. What are the precautions for developing a small program with mpvue? The following is a practical case, let's take a look.
1. ExampleLife cycle
In addition to the life cycle of Vue itself, mpvue is also compatible with the life cycle of small programs. The hooks of this part of the life cycle come from WeChat Page of the mini program, except for special circumstances, is not recommended to use the life cycle hook of the mini program.
app part:
onLaunch, initialize
onShow, when the applet starts, or Entering the foreground from the background displays
onHide. When the applet enters the background from the foreground,
page part:
onLoad, monitor page loading
onShow, monitor page display
onReady, monitor page initial rendering completed
onHide, monitor page hiding
onUnload, monitor page unloading
onPullDownRefresh, monitor user Pull-down action
onReachBottom, handler function for page pull-down event
onShareAppMessage, user clicks the upper right corner to share
onPageScroll, page scrolling
onTabItemTap, when the current tab page is clicked, triggered when tab is clicked (mpvue 0.0.16 supports)
Usage example:
new Vue({ data: { a: 1 }, created () { // `this` 指向 vm 实例 console.log('a is: ' + this.a) }, onShow () { // `this` 指向 vm 实例 console.log('a is: ' + this.a, '小程序触发的 onshow') } }) // => "a is: 1"
Note:
Do not use arrow functions on option properties or callbacks, such as created: () => console.log(this.a) or vm.$watch('a', newValue => this.myMethod()). Because arrow functions are bound to the parent context, this will not be the Vue instance as you would expect, and this.a or this.myMethod will be undefined.
The query parameter of the WeChat applet page is obtained through onLoad. mpvue has optimized this and directly passes this.$root.$mp.query To obtain the corresponding parameter data, its call needs to be used after the onLoad life cycle is triggered, such as onShow, etc.
2. Template syntax
Does not support pure-HTML
All BOM/DOM in the mini program cannot be used, which means that the v-html command cannot be used.
Does not support some complex JavaScript rendering expressions
We will directly encode the {{}} double curly brackets in the template into the wxml file. Due to the capability limitations of the WeChat applet (Data binding), complex JavaScript expressions cannot be supported.
Currently available are - * % ?: ! == === > < [] ., and the rest need to be improved.
Filters are not supported
The rendering part will be converted to wxml. wxml does not support filters, so this part of the function is not supported.
Function not supported
Using functions in methods within template is not supported.
List rendering
Full support for official documents: list rendering
Just need to pay attention to one thing,nested list rendering must specify different index!
<!-- 在这种嵌套循环的时候, index 和 itemIndex 这种索引是必须指定,且别名不能相同,正确的写法如下 --> <template> <ul v-for="(card, index) in list"> <li v-for="(item, itemIndex) in card"> {{item.value}} </li> </ul> </template></p> <h3 id="strong-a-href-http-www-php-cn-code-html-target-blank-Event-handler-a-strong"><strong><a href="http://www.php.cn/code/5688.html" target="_blank">Event handler</a></strong></h3> <p style="text-align: left;">The change event in input and textarea will be converted into a blur event. </p> <h4 id="strong-Note-strong"><strong>Note: </strong></h4> <ul class=" list-paddingleft-2"> <li> <p style="text-align: left;">#For native events not in the list, you can also use the bindregionchange event to directly change the bind to @# on the dom. ## @regionchange, at the same time, this event is also very special. It has two event types: begin and end<br>, which makes it impossible for us to distinguish what event it is in handleProxy, so you can listen to events at the same time when listening to such events. Both name and event type<br></p> <pre class="brush:php;toolbar:false"> <map @regionchange="functionName" @end="functionName" @begin="functionName"><map>
小程序能力所致,bind 和 catch 事件同时绑定时候,只会触发 bind ,catch 不会被触发,要避免踩坑。
事件修饰符
- .stop 的使用会阻止冒泡,但是同时绑定了一个非冒泡事件,会导致该元素上的 catchEventName 失效!
.prevent 可以直接干掉,因为小程序里没有什么默认事件,比如submit并不会跳转页面
.capture 支持 1.0.9
.self 没有可以判断的标识
.once 也不能做,因为小程序没有 removeEventListener, 虽然可以直接在 handleProxy 中处理,但非常的不优雅,违背了原意,暂不考虑
其他 键值修饰符 等在小程序中压根没键盘,所以。。。
三、组件
有且只能使用单文件组件(.vue 组件)的形式进行支持。其他的诸如:动态组件,自定义 render,和

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

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

Detailed explanation of the mode function in C++ In statistics, the mode refers to the value that appears most frequently in a set of data. In C++ language, we can find the mode in any set of data by writing a mode function. The mode function can be implemented in many different ways, two of the commonly used methods will be introduced in detail below. The first method is to use a hash table to count the number of occurrences of each number. First, we need to define a hash table with each number as the key and the number of occurrences as the value. Then, for a given data set, we run

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

Detailed explanation of the remainder function in C++ In C++, the remainder operator (%) is used to calculate the remainder of the division of two numbers. It is a binary operator whose operands can be any integer type (including char, short, int, long, etc.) or a floating-point number type (such as float, double). The remainder operator returns a result with the same sign as the dividend. For example, for the remainder operation of integers, we can use the following code to implement: inta=10;intb=3;

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

Detailed explanation of Linux system call system() function System call is a very important part of the Linux operating system. It provides a way to interact with the system kernel. Among them, the system() function is one of the commonly used system call functions. This article will introduce the use of the system() function in detail and provide corresponding code examples. Basic Concepts of System Calls System calls are a way for user programs to interact with the operating system kernel. User programs request the operating system by calling system call functions

Detailed explanation of Linux's curl command Summary: curl is a powerful command line tool used for data communication with the server. This article will introduce the basic usage of the curl command and provide actual code examples to help readers better understand and apply the command. 1. What is curl? curl is a command line tool used to send and receive various network requests. It supports multiple protocols, such as HTTP, FTP, TELNET, etc., and provides rich functions, such as file upload, file download, data transmission, proxy
