Commit 59366b1d by liangjianmin

error统一处理

parent 671c0e3d
...@@ -8,9 +8,10 @@ import qs from 'qs'; ...@@ -8,9 +8,10 @@ import qs from 'qs';
* @param {string} url 请求的接口URL * @param {string} url 请求的接口URL
* @param {object} param 传的参数,没有则传空对象 * @param {object} param 传的参数,没有则传空对象
*/ */
const envs = process.env.NODE_ENV;
let NODE_ENVS="/"; const envs = process.env.NODE_ENV;
switch (envs) { let NODE_ENVS = "/";
switch (envs) {
case 'development': case 'development':
//开发环境 //开发环境
NODE_ENVS = 'https://api.apiopen.top'; NODE_ENVS = 'https://api.apiopen.top';
...@@ -23,7 +24,7 @@ import qs from 'qs'; ...@@ -23,7 +24,7 @@ import qs from 'qs';
//线上环境 //线上环境
NODE_ENVS = '/'; NODE_ENVS = '/';
break; break;
} }
export const http = (method, url, param) => { export const http = (method, url, param) => {
param = param && typeof param === 'object' ? param : {}; param = param && typeof param === 'object' ? param : {};
const config = { const config = {
......
...@@ -4,6 +4,7 @@ import router from "./router"; ...@@ -4,6 +4,7 @@ import router from "./router";
import filters from './filters' import filters from './filters'
import directive from './directive' import directive from './directive'
import {http} from './ajax/index.js'; import {http} from './ajax/index.js';
import axios from 'axios'
//本地环境开启提示信息 //本地环境开启提示信息
...@@ -18,10 +19,17 @@ Object.keys(filters).forEach(key => Vue.filter(key, filters[key])); ...@@ -18,10 +19,17 @@ Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));
//加载自定义指令 //加载自定义指令
Vue.use(directive); Vue.use(directive);
axios.interceptors.response.use(res => {
return res;
}, error => {
console.log('error');
return Promise.reject(new Error(error))
})
//挂载到VUE原型上封装后的http请求 //挂载到VUE原型上封装后的http请求
Vue.prototype.$http = http; Vue.prototype.$http = http;
new Vue({ new Vue({
router, router,
render: (h) => h(App), render: (h) => h(App),
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<div class="index"> <div class="index">
我是首页 我是首页
<el-button @click="ceshi">element测试按钮</el-button> <el-button @click="ceshi">element测试按钮</el-button>
<Menu /> <Menu/>
</div> </div>
</template> </template>
...@@ -14,26 +14,23 @@ ...@@ -14,26 +14,23 @@
Button Button
} from 'element-ui' } from 'element-ui'
Vue.use(Button) Vue.use(Button)
export default { export default {
name: "index", name: "index",
data() { data() {
return { return {};
};
}, },
watch: {}, watch: {},
created() { created() {
}, },
computed: { computed: {},
},
methods: { methods: {
ceshi() { ceshi() {
this.$http('get', "/getJoke", { this.$http('get', "/getJoke1", {
page:1,count:2,type:'video' page: 1, count: 2, type: 'video'
}) })
.then(res => { .then(res => {
console.log(res) console.log(res)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment