提交 fa55f3e3 编写于 作者: Y yma16

feat:api跨域

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