Today, we will introduce the data binding of applets. today's content is followed by the introduction of mini-programs: the basic usage of components. if you are not clear about the content, you can review it on your own. Today, we will introduce the data binding of applets. today's content is followed by the introduction of mini-programs: the basic usage of components. if you are not clear about the content, you can review it on your own.
The text component is introduced in the previous lesson. the example of the previous lesson is as follows:
Case 1: If we want to dynamically display the content in text, we need to use data binding. data binding uses the Mustache syntax (double braces) to wrap the variables, it is identified by {TEXT. Use cases:
default primary
{{text}}
We will not see the text content during compilation. at this time, we need to define the text value in the data in newvip. js.
Data: {text: "This is the content of www.html 51.com "},
The compiled result is as follows:
In the same way, on the js page:
data:{
On the wxml page, bind data as follows:
default {{btnText}}
{{text}}
The results displayed after compilation are as follows:
What should we do if we want to modify the text content after clicking it? Simple
BtnClick: function () {console. log ("The button was clicked...") this. setData ({text: "this is the new 51 applet content "})}
The demo is as follows:
1. after clicking the button, no log is specified and no error message is displayed. There is almost no problem with the naked eye. In fact, there is a space between the bindtap click event bindtap = "btnClick" and>!
{{btnText}}
2. the dynamic data in WXML comes from the data of the corresponding Page.
More small programs: data binding related articles please follow the PHP Chinese network!