Axios发送请求

饿了么UI+VUE+axios向尚硅谷node后端验证登录。
遇到问题:传递参数时,如果只传递一个参数可以验证,但是传递账号+密码时提示让我输入密码。
解决:用字符串拼接,只传一个参数,第二个参数用&连接起来。

<template lang="">
    <div class="detail" style="display: flex;">
        <el-form :model="ruleForm" status-icon ref="ruleForm" label-width="100px"
            style="width: 32%;height: 50%;margin: auto;">
            <el-form-item label="登录账号:" prop="account" v-if="showArea">
                <el-input v-model="ruleForm.account" placeholder="请输入账号" style="width: 20rem;"></el-input>
            </el-form-item>
            <el-form-item label="注册账号:" prop="account1" v-if="showArea1">
                <el-input v-model="ruleForm.account1" placeholder="请输入注册账号" style="width: 20rem;"></el-input>
            </el-form-item>
            <el-form-item label="登录密码:" prop="pass" v-if="showArea">
                <el-input type="password" v-model="ruleForm.pass" autocomplete="off" placeholder="请输入密码"
                    style="width: 20rem;"></el-input>
            </el-form-item>
            <el-form-item label="注册密码:" prop="pass1" v-if="showArea1">
                <el-input type="password" v-model="ruleForm.pass1" autocomplete="off" placeholder="请输入注册密码"
                    style="width: 20rem;"></el-input>
            </el-form-item>
            <el-form-item>
                <!-- <el-button type="primary" @click="submitForm('ruleForm')" style="width: 20rem;" v-if="showArea">登录
                </el-button> -->
                <el-button type="primary" @click="denglu()" style="width: 20rem;" v-if="showArea">登录
                </el-button>
                <el-button type="primary" @click="submitForm('ruleForm1')" style="width: 20rem;" v-if="showArea1">注册
                </el-button>
                <el-link :underline="false" style="float: right;" v-on:click="topNone">{{qiehuan}}</el-link>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                ruleForm: {
                    pass: '',
                    account: '',
                    pass1: '',
                    account1: '',
                },
                showArea: true,//切换注册
                showArea1: false,//切换登录
                qiehuan:'去注册账号'
            };
        },
        methods: {
            // submitForm(formName) {
            //     const axios = require('axios');
            //     var params = new URLSearchParams();
            //     this.$refs[formName].validate((valid) => {
            //         if (valid) {
            //             params.append('username', 'admin2');
            //             params.append('password', '000000');
            //             axios.post('http://127.0.0.1:3007/api/login', params)
            //                 .then(function (value) {
            //                     console.log(value);
            //                 })
            //                 .catch(function (reason) {
            //                     console.log(reason);
            //                 });
            //         } else {
            //             console.log('error submit!!');
            //             return false;
            //         }
            //     });
            // },
            topNone() {
                if (this.showArea) {
                    this.showArea = false;
                    this.showArea1 = true;
                    this.qiehuan="去登录"
                } else {
                    this.showArea = true;
                    this.showArea1 = false;
                    this.qiehuan="去注册账号"
                }
            },
            denglu() {
                const that=this;
                const axios = require('axios');
                axios.post('http://127.0.0.1:3007/api/login', 'username='+that.ruleForm.account + '&password='+that.ruleForm.pass)
                    .then(function (value) {
                        console.log(value.data);
                    })
                    .catch(function (reason) {
                        console.log(reason);
                    });
            }
        },
    }
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值