1. 程式人生 > >小程式模板引入兩種方式

小程式模板引入兩種方式

頁面中用到地方比較多的模組,比如公共頭部或底部,可以寫成模板,用到的地方直接引入即可。

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:'要匯入的內容'}}"/>