WXML提供模板(template),可以在模板中定義代碼片段,然后在不同的地方調(diào)用。
補(bǔ)充:
? ? ? ? 1.事件:數(shù)據(jù)層到邏輯層的通訊方式。
模板
定義模板
使用 name 屬性者蠕,作為模板的名字
<template name="table">
? ? <view>
? ? ? ? ? ? <text>{{content}}</text>
? ? </view>
</template>
使用模板
使用 is 屬性,聲明需要的使用的模板掐松,然后將模板所需要的 data 傳入
<template is="table" data="{{...item}}"/>
Page({
????data: {
????????item: {
? ? ? ? ? ? index:0,msg:'this is a template',time:'2016-09-15'
????????????????}?
?????????}
})
注:模板的作用域:只能使用在data中定義了的數(shù)據(jù)以及模板定義文件中定義的 ? ? ? ? ? ? ?<wxs />?模塊踱侣。
引用
import
定義:可以在該文件使用目標(biāo)文件定義了的模板。
<import src="item.wxml"/>
<template is="item" data="{{text:'forbar'}}"/>
注:import不具有傳遞性大磺。
include
定義:可將目標(biāo)文件除<template/>和<wxl/>外的整個(gè)代碼都拷貝過(guò)來(lái)抡句。
<include src="content.wxml"/>