首页 > 应用开发 > IT综合 > Vue与SpringBoot简单前后分离demo
module.exports = {publicPath: '/admin',devServer: {port: 8080,disableHostCheck: true,proxy: {'^/api': {target: 'http://www.目标域名',changeOrigin: true, // 将主机标头的原点更改为目标URLpathRewrite: {'^/api': '/' //代理的路径}},}},}
onSubmit() {this.form.validateFields((err) => {if (!err) {this.logging = true;let code = this.form.getFieldValue("name");let password = this.form.getFieldValue("password");//记住我if (this.checked) {this.$store.dispatch("setLoginForm", {code: code,pass: password,checked: this.checked,});} else {this.$store.dispatch("setLoginForm", {});}// const encrypt = new JSEncrypt();// encrypt.setPublicKey(this.publicKey);// password = encrypt.encrypt(password);signIn({username: code,password: password,checkNum: this.form.getFieldValue("checkNum"),deviceId: this.deviceId,}).then((res) => {this.logging = false;if (res.rsCode == 0) {this.$ls.set("token", res.obj.token, 8 * 60 * 60 * 1000);this.$store.dispatch("保存位置", res.obj);this.$router.push("/路由位置");this.$notification["warning"]({message: "用户登录成功!",description: timeFix() + ",欢迎回来!",});} else {this.handleToggleCode();this.error = res.rsMsg;}});}});}
const service = axios.create({baseURL: BASE_URL, // api base_urltimeout: 60000, // 请求超时时间transformRequest: [function(data) {var ret = "";for (let it in data) {ret +=encodeURIComponent(it) + "=" + encodeURIComponent(data[it]) + "&";}const token = Vue.ls.get("token");if (token) {ret += "token=" + encodeURIComponent(token);}return ret;},],});
const err = (error) => {if (error.response) {const data = error.response.data;const token = Vue.ls.get("token");if (error.response.status === 403) {notification.error({message: "拒绝访问",});}if (error.response.status === 401 &&!(data.result && data.result.isLogin)) {notification.error({message: "用户未授权",description: "用户登录超时,请重新登录!",});if (token) {//退出操作并转向登录页Vue.ls.clear();//这里我在路由当中是做了设定,如果token为空会进入到登录页,所以只需要清除即可}}}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29797838/viewspace-2751582/ ,如需转载,请注明出处,否则将追究法律责任。