美文网首页
微信小程序-模版

微信小程序-模版

作者: OrochiZ | 来源:发表于2019-06-12 17:03 被阅读0次

    官方文档:https://developers.weixin.qq.com/miniprogram/dev/reference/wxml/template.html

    WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用

    1.定义模板
    • 使用 name 属性,作为模板的名字,便于以后调用
    • 模版可以定义在页面内,也可以定义在外部文件中
    • 定义外部文件中的模版只需要 2个文件即可:wxml和wxss
    <template name="msgItem">
      <view>
        <text> {{index}}: {{msg}} </text>
        <text> Time: {{time}} </text>
      </view>
    </template>
    
    2.调用模版
    <template is="msgItem" data="{{...item}}"/>
    
    • 如果是调用外部文件的模版,要在wxml文件中使用
      <import src="" />引入对应的wxml文件
    <import src="" />
    

    在wxss文件中引入对应的wxss文件

    @import "../../common.wxss";
    
    • is的值就模版的name属性值,代表要使用的是哪一个模版
    • data的值就是传入的数据

    相关文章

      网友评论

          本文标题:微信小程序-模版

          本文链接:https://www.haomeiwen.com/subject/vbalfctx.html