.wxml文件引用
WXML 提供两种文件引用方式import
和include
。
import
假设,在a.wxml文件中,引入item.wxml文件。
<!-- item.wxml -->
<template name="item">
<text>{{text}}</text>
</template>
<!-- a.wxml -
->
<import src="item.wxml"/>
<template is="item" data="{{text: 'forbar'}}"/>
//引入item.wxml后,在a.wxml中就可以使用item.wxml中定义的模板
import 有作用域的概念,即只会 import 目标文件中定义的 template,而不会 import 目标文件 import 的 template。
include
include
可以将目标文件
除了
<template/>
<wxs/>
外的整个代码引入,相当于是拷贝到
include
位置,如:
<!-- index.wxml -->
<include src="header.wxml"/>
<view> body </view>
<include src="footer.wxml"/>
<!-- header.wxml -->
<view> header </view>
<!-- footer.wxml -->
<view> footer </view>