美文网首页
12-template的使用

12-template的使用

作者: 早起的鸟儿 | 来源:发表于2019-11-07 19:05 被阅读0次

一、template的好处:可复用性高

  1. template目录结构
    pages--->templates--->swiper-template、tabs-template...
  2. template的使用

首先定义模板:swiper-template.wxml(相当于vue中的子组件)

<template name="swiper">
  <swiper>
    <swiper-item wx:for="{{swiperList}}" wx:key="index">
      <text>{{item.text}}</text>
    </swiper-item>
  </swiper>
</template>

其次在即将使用模板的.wxml中(相当于父级)引入模板

//<import src="../templates/swiper-template/swiper-template.wxml"/>
<import src="/pages/templates/swiper-template/swiper-template.wxml"/>

<template is="swiper"></template>//is对应模板中定义的name即可

但此时并不能正确显示,因为模板中用到的循环数据swiperList定义中在父级页面中,需要把传值到swiper-template.wxml中

<template is="swiper" data="{{swiperList,circular}}"></template>
//circular是swiper的一个属性,定义滑块循环滑动

️在data中可以传多个值,用逗号隔开即可
当然也可以把css放入到swiper-template.wxss,然后在父级页面的.wxss中引入

@import "/pages/templates/swiper-template/swiper-template.wxss";

同理:其他页面如果想用也可以上述一样的步骤引入swiper-template,然后传入相应的参数即可。

相关文章

  • iconfont的使用(下载使用)

    1、下载文件 2、在生命周期中引入项目 beforeCreate () { var domModule = ...

  • Gson的使用--使用注解

    Gson为了简化序列化和反序列化的过程,提供了很多注解,这些注解大致分为三类,我们一一的介绍一下。 自定义字段的名...

  • 记录使用iframe的使用

    默认记录一下----可以说 这是我第一次使用iframe 之前都没有使用过; 使用方式: 自己开发就用了这几个属...

  • with的使用

    下面例子可以具体说明with如何工作: 运行代码,输出如下

  • this的使用

    什么是this? this是一个关键字,这个关键字总是返回一个对象;简单说,就是返回属性或方法“当前”所在的对象。...

  • this的使用

    JS中this调用有几种情况 一:纯粹的函数调用 这是函数的最通常用法,属于全局性调用,因此this就代表全局对象...

  • ==的使用

    积累日常遇到的编码规范,良好的编码习惯,持续更新。。。 日常使用==用于判断的时候,习惯性将比较值写前面,变量写后...

  • this的使用

    1.默认绑定,就是函数立即执行。 函数立即执行就是指向window,但是如果是node环境,就是指向全局conso...

  • %in% 的使用

    写在前面:From 生信技能书向量难点之一:%in% 难点 (1)== 与 %in% 的区别== 强调位置,x和对...

  • QFramework的使用(UI Kit的使用)

    QFramework是GitHub上一款开源的框架,EMMMM就介绍到这吧 下面贴上框架的连接 Github:ht...

网友评论

      本文标题:12-template的使用

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