Skip to content

Commit aa44005

Browse files
author
spt
committed
跨域代理配置
1 parent c21a5d3 commit aa44005

File tree

7 files changed

+79
-49
lines changed

7 files changed

+79
-49
lines changed

config/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ module.exports = {
2727
autoOpenBrowser: true,
2828
assetsSubDirectory: 'static',
2929
assetsPublicPath: '/',
30-
proxyTable: {},
30+
proxyTable: {
31+
'/api-v1': {
32+
target: 'http://localhost:8081',
33+
changeOrigin: true
34+
}
35+
},
3136
// CSS Sourcemaps off by default because relative paths are "buggy"
3237
// with this option, according to the CSS-Loader README
3338
// (https://github.com/webpack/css-loader#sourcemaps)

doc/vue/跨域代理配置

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
当跨域无法请求的时候我们可以修改工程下config文件夹下的index.js中的dev:{}部分。dev: {
2+
env: require('./dev.env'),
3+
port: 8080,
4+
autoOpenBrowser: false,
5+
assetsSubDirectory: 'static',
6+
assetsPublicPath: '/',
7+
proxyTable: {
8+
'/api': {
9+
target: 'http://api.douban.com/v2',
10+
changeOrigin: true,
11+
pathRewrite: {
12+
'^/api': ''
13+
}
14+
}
15+
},
16+
// CSS Sourcemaps off by default because relative paths are "buggy"
17+
// with this option, according to the CSS-Loader README
18+
// (https://github.com/webpack/css-loader#sourcemaps)
19+
// In our experience, they generally work as expected,
20+
// just be aware of this issue when enabling this option.
21+
cssSourceMap: false
22+
}

src/components/platform/platform.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import PlatformService from '../../services/platform.service';
66
import moment from 'moment';
77
import debounce from 'throttle-debounce/debounce';
88
import { Vue, Prop, Component } from 'vue-property-decorator'
9-
109
import TodoListItem from '@/components/todo-list-item/TodoListItem.vue'
1110
import ZeusMenu from '@/components/zeus-menu/zeus-menu.vue';
11+
import ZeusUser from '@/components/zeus-user/zeus-user.vue';
1212
@Component({
1313
components: {
14-
ZeusMenu
14+
ZeusMenu,
15+
ZeusUser
1516
}
1617
})
1718
export default class PlatformComponent extends Vue {
@@ -38,7 +39,7 @@ export default class PlatformComponent extends Vue {
3839
companyInfo: any = null // 公司信息 - 修改
3940

4041
created() {
41-
// this.search();
42+
this.search();
4243
}
4344

4445
// 获取左侧列表接口

src/components/platform/platform.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</div>
1515
<div class="header-help">
1616
<el-button type="primary" @click="addNew">新增</el-button>
17-
<!--<zeus-user></zeus-user>-->
17+
<zeus-user></zeus-user>
1818
</div>
1919
</header>
2020
<transition name="fade" mode="out-in" v-if="navList.length">
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Vue, Component } from 'vue-property-decorator'
2+
//import Api from '../../services/login.js';
3+
import Clickoutside from 'element-ui/lib/utils/clickoutside';
4+
@Component({
5+
name: 'zeus-user',
6+
directives: { Clickoutside }
7+
})
8+
export default class UserComponent extends Vue {
9+
activeName:string= '';
10+
showDropDown:boolean= false;
11+
dropDown() {
12+
this.showDropDown = !this.showDropDown;
13+
}
14+
handleBlur() {
15+
this.showDropDown = false;
16+
}
17+
logout() {
18+
//const userInfo = JSON.parse(localStorage.getItem('userInfo'));
19+
// Api.logout({
20+
// token: userInfo.token,
21+
// accountId: userInfo.username
22+
// })
23+
// .then(({data}) => {
24+
// if (data.code === 1) {
25+
// this.$message({
26+
// message: '退出成功',
27+
// type: 'success'
28+
// });
29+
// setTimeout(() => {
30+
// location.href = '/login';
31+
// }, 500);
32+
// } else {
33+
// this.$message({
34+
// message: data.message,
35+
// type: 'warning'
36+
// });
37+
// }
38+
// });
39+
}
40+
}

src/components/user/index.vue renamed to src/components/zeus-user/zeus-user.vue

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,9 @@
1010
</transition>
1111
</div>
1212
</template>
13-
<script>
14-
import Api from '../../services/login.js';
15-
import Clickoutside from 'element-ui/lib/utils/clickoutside';
16-
export default {
17-
directives: { Clickoutside },
18-
data() {
19-
return {
20-
activeName: '',
21-
showDropDown: false
22-
};
23-
},
24-
methods: {
25-
dropDown() {
26-
this.showDropDown = !this.showDropDown;
27-
},
28-
handleBlur() {
29-
this.showDropDown = false;
30-
},
31-
logout() {
32-
const userInfo = JSON.parse(localStorage.getItem('userInfo'));
33-
Api.logout({
34-
token: userInfo.token,
35-
accountId: userInfo.username
36-
})
37-
.then(({data}) => {
38-
if (data.code === 1) {
39-
this.$message({
40-
message: '退出成功',
41-
type: 'success'
42-
});
43-
setTimeout(() => {
44-
location.href = '/login';
45-
}, 500);
46-
} else {
47-
this.$message({
48-
message: data.message,
49-
type: 'warning'
50-
});
51-
}
52-
});
53-
}
54-
}
55-
};
13+
<script lang="ts">
14+
import ZeusUserComponent from '@/components/zeus-user/zeus-user.component'
15+
export default ZeusUserComponent
5616
</script>
5717
<style scoped lang="scss">
5818
.user {

src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import Vue from 'vue'
77
import App from './App.vue'
88
import router from './router'
9-
9+
import axios from 'axios';
1010
import ElementUI from 'element-ui'
1111
import 'element-ui/lib/theme-default/index.css'
1212
import InfiniteScroll from 'vue-infinite-scroll';
1313
import './assets/css/index.scss';
1414
import 'font-awesome/css/font-awesome.css';
15+
16+
axios.defaults.baseURL = '/api-v1/';
1517
Vue.use(ElementUI)
1618
Vue.use(InfiniteScroll)
1719
/* eslint-disable no-new */

0 commit comments

Comments
 (0)