美文网首页
template模板

template模板

作者: ibiaoma | 来源:发表于2018-11-26 16:50 被阅读7次

有时候需要复用页面的某一块区域,包括样式,可以考虑template

template.wxml
<template name="detailTemplate">
    <view>
      <image></image>
      <text></text>
    </view>
</template>
这个name要与外面的对应
template.wxss
就是template.wxml中各标签的样式
例如:
.tmpContainer{
  display: flex;
  flex-direction: column;
  border-top: 1px solid #efefef;
  /* border-bottom: 1px solid #efefef; */
  padding: 5px 0;
  margin: 20rpx 0 40rpx
}
使用

1、在wxml中导入template.wxml

导入:
<import src="/pages/template/template" />

使用如普通标签
 <template is="detailTemplate"></template>
注:此处的 is  与模板内的name 一样

2、在wxss中导入template.wxss

直接@import '路径'即可

如: @import '/pages/template/template.wxss';

相关文章

网友评论

      本文标题:template模板

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