007-01、微信小程序---组件之swiper(tab切换)

此tab切换以登录页面为参照。
1、WXMl

<view class="tab-title">
    <block wx:for="{{msg}}" wx:key="mykey">
        <view class="tab-name {{currentTab==item.mykey ? 'on' : ''}}" data-current="{{item.mykey}}" bindtap="switchNav">{{item.name}}</view>
    </block>
</view>
<view>
    <form bindsubmit="formSubmit" bindreset="formReset" class="formBox">
        <swiper class="swiper-box" current="{{currentTab}}" duration="300" bindchange="bindchange" style="height:{{winHeight - 148}}px">
            <swiper-item>
                <view class="lines">
                    <view class="lines_text">真实姓名</view>
                    <view class="lines_inp">                
                        <input type="text" />
                    </view>
                </view>
                <view class="lines">
                    <view class="lines_text">手机号码</view>
                    <view class="lines_inp">                
                        <input type="text" />
                    </view>
                </view>
                <view class="lines">
                    <view class="lines_text">昵称</view>
                    <view class="lines_inp">                
                        <input type="text" />
                    </view>
                </view>
                <view class="lines">
                    <view class="lines_text">密码</view>
                    <view class="lines_inp">                
                        <input type="text" password="true" />
                    </view>
                </view>
                <view class="lines">
                    <view class="lines_text">确认密码</view>
                    <view class="lines_inp">                
                        <input type="text" password="true" />
                    </view>
                </view>
                <button class="btns" bindconfirm="register">注册</button>
            </swiper-item>
            <swiper-item>
                <view class="lines">
                    <view class="lines_text">用户名</view>
                    <view class="lines_inp">                
                        <input type="text" placeholder="" />
                    </view>
                </view>
                <view class="lines">
                    <view class="lines_text">密码</view>
                    <view class="lines_inp">                
                        <input type="text" password="true" />
                    </view>
                </view>
                <button class="btns" bindconfirm="logIn">登录</button>
            </swiper-item>
        </swiper>

    </form>
</view>

2、WXSS

.tab-title{
    display: flex;
    display: -webkit-flex;
    width: 86%;
    margin: 150rpx 7% 0;
    /*border-bottom: 1px solid #ccc;*/
}
.tab-name{
    width: 50%;
    height: 100rpx;
    line-height: 100rpx;
    text-align: center;
}
.on{
    color: blue;
    border-bottom: 2px solid blue;
}
.swiper-box{
    display: block;
    width: 86%;
    height: 600px;
    margin: 20rpx 7%;
}
.lines{
    display: flex;
    display: -webkit-flex;
    width: 100%;
    border-bottom: 1px solid #ccc;
}
.lines_text{
    width: 30%;
    height: 100rpx;
    line-height: 100rpx;
}
.lines_inp{width: 70%;}
.lines_inp input{
    width: 100%;
    height: 100rpx;
    line-height: 100rpx;
}
.btns{
    width: 98%;
    margin: 100rpx 1% 0;
    background: rgba(100,100,255,0.5);
}

3、JS


Page({
    data: {
        msg: [],
        currentTab: 0,
        winWidth: 0,  
        winHeight: 0

    },
    onLoad: function () {
        var that = this;
        wx.getSystemInfo( {  

          success: function( res ) {  
            that.setData( {  
              winWidth: res.windowWidth,  
              winHeight: res.windowHeight  
            });  
          }  

        });  
        that.setData({
            msg: [
                {
                    "name":"注册",
                    "mykey":0
                    // "inputName":
                    //  ["真实姓名","手机号码","昵称","密码","确认密码"]
                },
                {
                    "name":"登录",
                    "mykey":1
                    // "inputName":["用户名","密码"]
                }
            ]

        });
    },
    switchNav: function (e) {
        var that = this;
        that.setData({
            currentTab: e.target.dataset.current
        })
    },
    bindchange: function (e) {
        var that = this;
        that.setData({
            currentTab: e.detail.current
        })
    },
    register: function () {

    }

})

温馨提示:扫码可以提问、交流。本人有各个行业的小程序前端代码,如有需要也可以扫码留言哦。
这里写图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值