微信程序开发小程序交互

前端开发工具

需要用到的

login.wxml

<view>

    <image src="/asset/b.jpg" mode="scaleToFill"/>

    <view>

        <input placeholder="请输入用户名" maxlength="11" bind:input="changeValue" data-label="account"/>

    </view>

    <view>

        <input placeholder="请输入密码" password="{ {true}}" bind:input="changeValue" maxlength="16" data-label="password"/>

    </view>

    <view>

        <button bindtap="userLogin" type="primary">登录</button>

    </view>

</view>

调节大小login.wxss

input {

    width: 90%;

    line-height: 40px;

    border: 1px solid gray;

    border-bottom: 2px solid green;

    display: block;

    margin: 10px auto;

    height: 40px;

}

image {

    width: 300px;

    height: 300px;

    border-radius: 50%;

    display: block;

    margin: auto;

}

login.js

import {request} from "../../request/index";

Page({

    data: {

        user: {

            account: "",

            password: ""

        }

    },

    changeValue(e) {

        let property = "user." + e.target.dataset.label

        let value = e.detail.value

        this.setData({

            [property]: value

        })

    },

    userLogin() {

        wx.showLoading({

            title: "正在努力加载中",

            mask: false

        })

        request("/user/login", this.data.user).then(res => {

            console.log(res)

            wx.hideLoading()

            let icon = "error"

            if (res.data.code === 200) {

                icon = "success"

            }

            wx.showToast({

                title: res.data.message,

                icon

            })

        }).catch(res => {

            console.error(res)

            wx.hideLoading()

        })

    }

})

 

 运行界面

后端开发

有兴趣的可以私信我  提供源码

猜你喜欢

转载自blog.csdn.net/m0_60375943/article/details/123410704