import 可以在该文件中使用目标文件定义的template,如
在helloworld.wxml中定义了一个叫msgItem和item的tempalte:
<template name="msgItem">
<view>
<text>{{index}}:{{msg}}</text>
<text>Time:{{time}}</text>
</view>
</template>
<template is="msgItem" data="{{...item}}"/>
<template name="item">
<text>{{text}}</text>
</template>
在index.wxml中引用了helloworld.wxml,就可以使用helloworld.wxml.wxml模板
<import src="/pages/helloworld/helloworld.wxml"/>
<template is="msgItem" data="{{...item}}" />
<template is="item" data="{{text:'forbar'}}" />
另外需要注意:
import 有作用域的概念,即只会 import 目标文件中定义的 template,而不会 import 目标文件 import 的 template。
如:C import B,B import A,在C中可以使用B定义的template,在B中可以使用A定义的template,但是C不能使用A定义的template。
运行结果: