頁面中用到地方比較多的模塊,比如公共頭部或底部,可以寫成模板,用到的地方直接引入即可。
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:'要導入的內容'}}"/>