在public.js中
import axios from 'axios';
const web_url = 'http://www.zhangsan.com';
export function getDept() {
let arr = [];
axios.get(web_url + '/comboboxDept2', {
params: {
page: 1,
limit: 10,
id: 1
}
})
.then((response) => {
arr = response;
console.log(response);
})
.catch((reject) => {
console.log(reject)
})
return arr;
}
在同级目录index.vue中
import { getDept } from './public.js';
export default {
data() {
},
created(){
console.log(getDept());
},
}
结果数据