由于微信小程序文件大小的限制,可以把一些公用的文件 單離出來形成模板,從而被各個模板引用:
定義模板第一種方式:
新建一個目錄:
寫入:
text>hello worldtext>
模板引入:(這里引入后面一定要有反斜杠 ? / ?)
include src="../template/header" />
定義模板第二種方式:
定義一個 common.wxml 文件
寫入:
template name="header">
這里是頭部
template>
template name="footer">
這里是底部
template>
這種方法引入是通過 import 方法: 主要反斜杠
import src="../template/common.wxml" />
template id=‘header‘ />
template id=‘footer‘ />
使用第二種方法:還可以進行傳遞參數(shù):
template name="header">
{{header}}
template>
template name="footer">
{{footer}}
template>
引入:
import src="../template/common.wxml" />
template id=‘header‘ data="{{header:‘這里是頭部‘}}" />
template id=‘footer‘ data="{{footer:‘這里是底部‘}}" />
?
微信小程序 --- 模板的使用
聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進行處理。