微信小程序怎么使用template模块?比如template写一个登录弹框

干什么的?啥时候会用到?
微信的模版主要是用于公共界面管理,比如弹窗或公共页面都可以用模版定义。
一.微信小程序怎么使用template模块?
1.创建模板文件
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200624205419406.png
2.index.wxml=>

<template name="apifmLogin">
  <view class="apifmLogin" hidden="{{wxlogin}}">
    <view class="s-b">
      <view class="s-l-b">
        <image src="/images/login.png" style="width:180rpx;height:130rpx;margin-left:160rpx;" />
        <text>授权登录</text>
      </view>
      <view class="s-t-b">
        <view class="s-t-i">
          <text>·</text>请授权小程序登录</view>
        <view class="s-t-i">
          <text>·</text>我们不会公布您的这些信息</view>
        <view class="s-t-i">
          <text>·</text>只是为了给您提供更好的服务</view>
      </view>
      <button class="l" catchtap="yx" style="line-height:30rpx;">允许</button>
      <button class="c" catchtap="zb" type="default" style="line-height:30rpx;">暂不登录</button>
    </view>
  </view>
</template>

3.在所用到的页面中引入

<import src="/template/login/index.wxml" />

4.所用到的页面中

<template is="apifmLogin"  data="{{wxlogin:!show}}" />

里面的is和定义的template里的name相对应
注意:
如果模板中有js相关的操作或者引入了变量,这些变量和方法必须写在引入模板的js文件中,使用的变量必须通过 template 的data属性传递,data里面的变量和template标签里面的相对应

在js中定义要传递的变量
show:false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值