-
import
-
用法
- import可以在该文件中使用目标文件定义的template
-
例子
-
template模板定义
- <!-- item.wxml -->
<template name="item">
<text>{{text}}</text>
</template>
-
另一个文件引用模板
- <import src="item.wxml"/>
<template is="item" data="{{text: 'forbar'}}"/>
-
作用域
- 只会 import 目标文件中定义的 template,
而不会 import 目标文件 import 的 template
-
例子
- C import B,B import A,在C中可以使用B定义的template,
在B中可以使用A定义的template,但是C不能使用A定义的template
-
include
-
用法
- include可以将目标文件除了<template/>的整个代码引入,相当于是拷贝到include位置
-
例子
- <!-- header.wxml -->
<view> header </view>
- <!-- footer.wxml -->
<view> footer </view>
- <!-- index.wxml -->
<include src="header.wxml"/>
<view> body </view>
<include src="footer.wxml"/>