微信小程序怎么使用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

猜你喜欢

转载自blog.csdn.net/lqlq54321/article/details/106950945