On this page
Introduction
WXML is a set of tag languages API capabilities、Event system, it can build the structure of the page.
Use the following simple examples to see what WXML has:
Data binding
js
<!--wxml-->
<view> {{message}} </view>js
// page.js
Page({
data: {
message: 'Hello MINA!'
}
})List Rendering
js
<!--wxml-->
<view wx:for="{{array}}"> {{item}} </view>js
// page.js
Page({
data: {
array: [1, 2, 3, 4, 5]
}
})Conditional Rendering
js
<!--wxml-->
<view wx:if="{{view == 'WEBVIEW'}}"> WEBVIEW </view>
<view wx:elif="{{view == 'APP'}}"> APP </view>
<view wx:else="{{view == 'MINA'}}"> MINA </view>js
// page.js
Page({
data: {
view: 'MINA'
}
})Template
js
<!--wxml-->
<template name="staffName">
<view>
FirstName: {{firstName}}, LastName: {{lastName}}
</view>
</template>
<template is="staffName" data="{{...staffA}}"></template>
<template is="staffName" data="{{...staffB}}"></template>
<template is="staffName" data="{{...staffC}}"></template>js
// page.js
Page({
data: {
staffA: {firstName: 'Hulk', lastName: 'Hu'},
staffB: {firstName: 'Shang', lastName: 'You'},
staffC: {firstName: 'Gideon', lastName: 'Lin'}
}
})