//这里是vue代码,地址为http://127.0.0.1:8000
login(){
this.$refs.userRef.validate(valid =>{
if(!valid) return
//登录操作
const {data:res} = this.$axios.post('/user/login',this.$qs.stringify(this.userForm))
console.log(res)
})
},
//下面是flask代码,地址为http://127.0.0.1:5000
@user.route('/login', methods=['POST'])
def login():
name = request.form.get("name")
pwd = request.form.get("pwd")
if not all([name, pwd]):
return {"status": 400, "msg": "登录失败,输入的数据不完整"}
else:
sql = "select id from user where name = %s and pwd = %s"
dbutil = DBUtil()
user_result = dbutil.quary_one(sql, name, pwd)
if user_result:
user_id = user_result[0]
utoken = generate_token(user_id)
return to_dict_msg(200, data={'token': utoken.decode("utf-8")})
return "hello"
//下面是vue.config.js
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})
//下面是main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import { Button, Select,Form,FormItem,Input } from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import qs from 'qs'
Vue.config.productionTip = true
Vue.use(Button).use(Select).use(Form).use(FormItem).use(Input);
Vue.prototype.$axios = axios
Vue.prototype.$qs = qs
axios.defaults.baseURL = 'http://localhost:5000'
new Vue({
router,
render: h => h(App)
}).$mount('#app')
用vue2写的一个登录页面,跳到写好的flask登录后端,出现了axios跨域请求错误,看了几篇博客,还是不知道咋改,请教友友们
最新推荐文章于 2023-12-02 12:30:24 发布