提交 fa55f3e3 编写于 作者: Y yma16

feat:api跨域

上级 b607b035
'use strict'
"use strict";
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
const path = require("path");
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
assetsSubDirectory: "static",
assetsPublicPath: "/",
proxyTable: {
'/api': {
target: 'http://yongma16.xyz', //后端接口地址
"/api/": {
target: "http://114.116.52.53/", //后端接口地址
ws: true, //接受websocket请求
changeOrigin: true, //是否允许跨越
chunkOrigins: true,
pathRewrite: {
'^/api': '' //重写,
}
}
"^/api": "", //重写,
},
},
"/ws_api/": {
target: "ws://114.116.52.53/",
ws: true, //接受websocket请求
changeOrigin: true, //是否允许跨越
chunkOrigins: true,
pathRewrite: {
"^/ws_api": "", //重写,
},
},
},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
host: "localhost", // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
......@@ -42,24 +51,24 @@ module.exports = {
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'cheap-module-eval-source-map',
devtool: "cheap-module-eval-source-map",
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
cssSourceMap: true
cssSourceMap: true,
},
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
index: path.resolve(__dirname, "../dist/index.html"),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',
assetsRoot: path.resolve(__dirname, "../dist"),
assetsSubDirectory: "static",
assetsPublicPath: "./",
/**
* Source Maps
......@@ -67,19 +76,19 @@ module.exports = {
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
devtool: "#source-map",
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
productionGzipExtensions: ["js", "css"],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}
bundleAnalyzerReport: process.env.npm_config_report,
},
};
......@@ -45,7 +45,7 @@ export default {
return {
noneMsg: "还没人评论>_<",
msg: "评论区",
baseurl: "http://114.116.52.53/comment/",
baseurl: "api",
// baseurl: "http://yongma16.xyz/comment/",
userImg: "",
username: "匿名",
......@@ -97,7 +97,7 @@ export default {
};
console.log("获取评论id", params.articleId);
axios
.post(that.baseurl + "get/", params)
.post(that.baseurl + "comment/get/", params)
.then((res) => {
try {
let resData = res.data;
......@@ -141,7 +141,7 @@ export default {
content: content,
};
axios
.post(that.baseurl + "post/", params)
.post(that.baseurl + "comment/post/", params)
.then((res) => {
that.articleCommit = null;
try {
......
......@@ -224,7 +224,7 @@ export default {
data() {
return {
// baseurl: '/api/',
baseurl: "http://114.116.52.53/",
baseurl: "/api/",
// baseurl: "http://yongma16.xyz/",
msg: "内容",
commmentSlogan: "评论区",
......
......@@ -37,7 +37,7 @@ export default {
msg: "css练习:",
css_length: "",
// baseurl: 'http://127.0.0.1:1998',
baseurl: "http://114.116.52.53/",
baseurl: "/api/",
// baseurl: "http://yongma16.xyz/",
css_title: [],
css_path: [],
......
......@@ -43,36 +43,36 @@
</template>
<script>
import axios from 'axios'
import store from '@/store'
import axios from "axios";
import store from "@/store";
export default {
name: 'Login',
data () {
name: "Login",
data() {
var checkName = (rule, value, callback) => {
if (!value) {
return callback(new Error('账号不能为空'))
return callback(new Error("账号不能为空"));
}
setTimeout(() => {
// if (!Number.isInteger(value)) {
// callback(new Error('请输入密码'));
// } if {
if (value.length < 2) {
callback(new Error('名字至少两位'))
callback(new Error("名字至少两位"));
} else {
callback()
}
}, 1000)
callback();
}
}, 1000);
};
var validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入密码'))
if (value === "") {
callback(new Error("请输入密码"));
} else {
// if (this.ruleForm.checkPass !== '') {
// this.$refs.ruleForm.validateField('checkPass');
// }
callback()
}
callback();
}
};
// var validatePass2 = (rule, value, callback) => {
// if (value === '') {
// callback(new Error('请再次输入密码'));
......@@ -84,68 +84,68 @@ export default {
// };
return {
// baseurl:"http://127.0.0.1/user/login/",
baseurl: 'http://114.116.52.53/',
baseurl: "/api/",
// baseurl: 'http://yongma16.xyz/user/login/',
ruleForm: {
pass: '',
pass: "",
// checkPass: '',
name: ''
name: "",
},
rules: {
pass: [{ validator: validatePass, trigger: 'blur' }],
checkPass: [{ validator: validatePass, trigger: 'blur' }],
name: [{ validator: checkName, trigger: 'blur' }]
}
}
pass: [{ validator: validatePass, trigger: "blur" }],
checkPass: [{ validator: validatePass, trigger: "blur" }],
name: [{ validator: checkName, trigger: "blur" }],
},
};
},
methods: {
submitForm (formName) {
const that = this // this指向
submitForm(formName) {
const that = this; // this指向
this.$refs[formName].validate((valid) => {
if (valid) {
// 提交数据
console.log(that.ruleForm.name, that.ruleForm.pass)
console.log(that.ruleForm.name, that.ruleForm.pass);
// axios提交数据 post
const loginUrl = that.baseurl + 'user/login/'
const loginUrl = that.baseurl + "user/login/";
const userInfo = {
name: that.ruleForm.name,
password: that.ruleForm.pass
}
password: that.ruleForm.pass,
};
axios
.post(loginUrl, userInfo)
.then((res) => {
// alter('提交中');
console.log(res.data)
console.log(res.data);
if (res.data.code == 1) {
localStorage.setItem('yma16siteUserInfoName', userInfo.name)
localStorage.setItem('yma16siteUserInfoPwd', userInfo.password)
store.commit('setUserInfo', userInfo) // store信息
console.log('return login success!')
document.cookie = `user=${that.ruleForm.name}`
that.$router.push({ path: '/' })
localStorage.setItem("yma16siteUserInfoName", userInfo.name);
localStorage.setItem("yma16siteUserInfoPwd", userInfo.password);
store.commit("setUserInfo", userInfo); // store信息
console.log("return login success!");
document.cookie = `user=${that.ruleForm.name}`;
that.$router.push({ path: "/" });
// 添加cookie
} else if (res.data.code == 0) {
// alter("失败!")
console.log('失败', res)
console.log("失败", res);
}
// that.$cookies.set('')
})
.catch((res) => {
console.log('post失败')
console.log(res)
})
console.log("post失败");
console.log(res);
});
} else {
alert('请输入账号密码')
console.log('请输入账号密码')
return false
alert("请输入账号密码");
console.log("请输入账号密码");
return false;
}
})
});
},
resetForm (formName) {
this.$refs[formName].resetFields()
}
}
}
resetForm(formName) {
this.$refs[formName].resetFields();
},
},
};
</script>
<style scoped>
......
......@@ -22,7 +22,7 @@ export default {
name: "Mavoneditor",
data() {
return {
baseurl: "http://114.116.52.53/",
baseurl: "/api/",
basePath: "admin/",
// baseurl: 'http://yongma16.xyz/',
md_data: [],
......
......@@ -141,9 +141,9 @@ export default {
room_name: ["DjangoVue"],
room_select: "",
// baseUrl: "http://localhost:8006/webchat/index/",
baseurl: "http://114.116.52.53/",
baseurl: "/api/",
// baseUrl: "http://yongma16.xyz/",
websocketUrl: "ws://114.116.52.53/",
websocketUrl: "/ws_api/",
// websocketUrl: "yongma16.xyz/ws/webchat/",
websocket: null,
// room 存房间名字,content保存聊天信息的数组
......
......@@ -116,7 +116,7 @@ export default {
register_success: false,
register_error: false,
// baseurl: "http://127.0.0.1/",
baseurl: "http://114.116.52.53/",
baseurl: "/api/",
// baseurl: 'http://yongma16.xyz/',
ruleForm: {
pass: "",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册