search
HomeWeChat AppletMini Program DevelopmentWeChat Mini Program: Data Binding Explanation

WeChat Mini Program: Data Binding Explanation

Mar 01, 2017 am 11:27 AM
WeChat applet

What I want to introduce to you today is the data binding of the mini program. Today’s content follows the WeChat mini program: the basic use of components. Students who are unclear can review it by themselves.
We talked about the text component in the last class. The example in the previous class is as follows:

WeChat Mini Program: Data Binding Explanation

Case 1: If we want to dynamically display the content in the text, You need to use data binding. Data binding uses Mustache syntax (double curly brackets) to wrap variables and identifies them with {{TEXT}}. The following use case:

<button type="default"  hover-class="other-button-hover"> default </button>
<button type="primary" > primary </button>

<text>{{text}}</text>

We will not be able to see the text content when compiling. At this time, we need to define the value of text in the data in newvip.js

  data:{
    text:"这是www.html51.com的内容"
  },

The results displayed after compilation are as follows :

WeChat Mini Program: Data Binding Explanation

Case 2: If we want to display the content on the button through data binding, how should we implement it. (The text of the button in the above use case is primary)
Same method, on the js page:

<blockquote>  data:{

Use data binding on the wxml page as follows:

<button type="default"  hover-class="other-button-hover"> default </button>
<button type="primary" > {{btnText}} </button>

<text>{{text}}</text>

The results displayed after compilation As shown in the figure below:

WeChat Mini Program: Data Binding Explanation

#3. The method of using data binding is as mentioned above. What if the content in the data binding is dynamically changed?
The method is also very simple. In order to be able to see the dynamic changes in the data during the demonstration, we first add a click event to the button.

<div>  btnClick: function() {</div><div>      console.log("按钮被点击了...")</div><div>  }</div>
<button type="primary" bindtap="btnClick" > {{btnText}} </button>

When we compile, we will print out a log: the button was clicked..., let's take a look at the demonstration effect:

WeChat Mini Program: Data Binding Explanation

If we want to click , how do we modify the text content? Very simple

  btnClick: function() {
      console.log("按钮被点击了了...")

      this.setData({text:"这是新的51小程序内容"})
  }

The demonstration effect is as follows:

WeChat Mini Program: Data Binding Explanation

Note: Problems that may be encountered during the above operation
1. No log is specified after clicking the button When printed, there is no error message. The problem is almost invisible to the naked eye. In fact, it is an extra space between bindtap="btnClick" and > in the bindtap click event!

<button type="primary" bindtap="btnClick" > {{btnText}} </button>

2. The dynamic data in WXML comes from the data of the corresponding Page.

For more WeChat applet: data binding explanation and related articles, 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software