Home > WeChat Applet > Mini Program Development > WeChat applet reference tutorial

WeChat applet reference tutorial

高洛峰
Release: 2018-05-15 10:20:39
Original
2486 people have browsed it

This article mainly introduces the relevant information cited by WeChat applet, and attaches simple example code. Friends in need can refer to the

series of articles:

WXSS of WeChat applet tutorial
Quotation of WeChat Mini Program Tutorial
Events of WeChat Mini Program Tutorial
Template of WeChat Mini Program Tutorial
List Rendering of WeChat Mini Program Tutorial
Conditional Rendering of WeChat Mini Program Tutorial
Data Binding of WeChat Mini Program Tutorial
WXML of WeChat Mini Program Tutorial

Reference

WXML provides two file reference methods, import and include.

import

import can use the template defined by the target file in this file, such as:

in item.wxml A template called item is defined in:

<!-- item.wxml -->
<template name="item">
 <text>{{text}}</text>
</template>
Copy after login

If item.wxml is referenced in index.wxml, you can use the item template:

<import src="item.wxml"/>
<template is="item" data="{{text: &#39;forbar&#39;}}"/>
Copy after login

import scope

Import has the concept of scope, that is, it will only import the template defined in the target file, but not the template imported by the target file.
For example: C import B, B import A, the template defined by B can be used in C, and the template defined by A can be used in B, but C cannot use the template defined by A.

<!-- A.wxml -->
<template name="A">
 <text> A template </text>
</template>
Copy after login
<!-- B.wxml -->
<import src="a.wxml"/>
<template name="B">
 <text> B template </text>
</template>
Copy after login
<!-- C.wxml -->
<import src="b.wxml"/>
<template is="A"/> <!-- Error! Can not use tempalte when not import A. -->
<template is="B"/>
Copy after login

include

include can introduce the entire code of the target file out of