页面中用到地方比较多的模块,比如公共头部或底部,可以写成模板,用到的地方直接引入即可。
1.include的用法
templates/footer.html
<text>要用的公共底部</text>
index.wxml中引用footer直接如下所示即可:
<include src="/templates/footer"/>
2.import的用法
templates/header.html
<template name="header1">
这是头部内容1----{{text}}
</template>
<template name="header2">
这是头部内容2----{{text}}
</template>
index.wxml中引用header要用is来标记引入的是哪一个模板,需要动态插入文本的话,用data。
<template is="header1" data="{{text:'要导入的内容'}}"/>