标签:成功 交流 mod == OLE 方法 parser express row
<template>
<div class="LoginForm">
<el-form ref="form" label-width="80px" action="api/info">
<!--<myCanvas></myCanvas>-->
<el-row>
<el-col :span="8"><div class="grid-content"></div></el-col>
<el-col :span="8">
<div class="grid-content login">
<p class="loginTitle">登录 | Login</p>
<el-input type="text" v-model="userName" placeholder="请输入你的用户名"></el-input>
<el-input type="password" v-model="ori_password" placeholder="请输入你的密码"></el-input>
<el-button type="info" @click="login">登录</el-button>
<el-button type="info" @click="dialogFormVisible = true">注册</el-button>
<!--<el-button type="warning" @click="findPasswordVisible = true" style="float: right">找回密码</el-button>-->
</div>
</el-col>
<el-col :span="8"><div class="grid-content"></div></el-col>
</el-row>
</el-form>
</div>
</template>
<script>
import store from ‘../store/index‘
export default {
name: "LoginForm",
data() {
return {
userName: ‘‘,
ori_password: ‘‘,//原始未加密
}
},
methods: {
login() {
this.password = this.ori_password
this.$http.post(‘api/login‘, {
username: this.userName,
password: this.password}
).then((response) => {
this.loginResponse(response)
}, (response) => {
console.log(response)
}
)
},
loginResponse(response){
let body = response.data;
if(body.state === ‘登录成功‘){
this.$router.push(‘/home‘);}
//let userid = body.id;
//this.$store.dispatch(‘setUsername‘, {name: this.userName, id:userid, token:body.token});}
else this.$router.push(‘/‘);
}
}
}
</script>
dev: {
env: require(‘./dev.env‘),
host:‘localhost‘,
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: ‘static‘,
assetsPublicPath: ‘/‘,
proxyTable: {
‘/api/‘ : {
target:‘http://localhost:3000/‘,
changeOrigin: true,
}
},
cssSourceMap: false
},
const userApi = require(‘./api/userApi‘);
const fs = require(‘fs‘);
const path = require(‘path‘);
const bodyParser = require(‘body-parser‘);
const cookieParser = require(‘cookie-parser‘)
const cors = require(‘cors‘);
const express = require(‘express‘);
const app = express();
app.use(cors({
origin:[‘http://localhost:8080‘],
methods:[‘GET‘,‘POST‘],
alloweHeaders:[‘Conten-Type‘, ‘Authorization‘]
}));
app.set(‘port‘, (process.env.port || 3000))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}))
app.use(cookieParser())
app.use(userApi)
app.listen(app.get(‘port‘), function () {
console.log(‘Visit http://localhost:‘ + app.get(‘port‘))
})
router.post(‘/api/login‘, function (req, res) {
let userName = req.body.username,
password = req.body.password,
resBody = {state: ‘‘}
if (userName !== undefined && userName.length > 0) {
conn.query("SELECT * FROM users WHERE ?", {name: userName}, function (err, doc) {
if (err) {
resBody.state = ‘账号不存在‘;
res.send(resBody);
} else {
if (doc.length === 0) {
resBody.state = ‘账号不存在‘;
res.send(resBody);
} else {
console.log(doc);
resBody.state = ‘登录成功‘;
res.send(resBody);
}
}
})
}
else {
resBody = {state: ‘请输入用户名‘}
res.send(resBody)
}
});
标签:成功 交流 mod == OLE 方法 parser express row
原文地址:https://www.cnblogs.com/colorfulhw/p/9164996.html