import有作用域的概念,即只会import目标文件中定义的template,而不会import目标文件import的template。
如:C import B,B import A,在C中可以使用B定义的template,在B中可以使用A定义的template,但是C不能使用A定义的template。
<!-- A.wxml -->
<template name="A">
<text>A 模板</text>
</template>
<!-- B.wxml -->
<import src="A.wxml">
<template name="B">
<text>B 模板</text>
</template>
<!-- C.wxml -->
<import src="B.wxml">
<template is="A"/> <!-- 报错:没有import A模板时,不能使用A模板 -->
<template is="B"/>
include
include可以将目标文件除了<template/> <wxs/>外的整个代码引入,相当于是拷贝到include位置,如:
<!-- index.wxml -->
<include src="header.wxml"/>
<view>body</view>
<include src="fotter.wxml"/>
<!-- header.wxml -->
<view>header</view>
<!-- fotter.wxml -->
<view>fotter</view>