vue接口请求200 返回空白_vue 请求公共接口

需求:有几组数据,是好多页面都需要的,后台给每组数据写到一个接口里了,所以我需要请求多个公共接口,我的想法就定义了一个公共js,然后所需的页面去引用;

第一种方法:

common.js:

 var commonObj ={    async GetDepartment(fn){    var a =await axios.post('/api/common/getDepartment');    fn(a)  }};export default commonObj 

所需的vue页:

import commonObj  from '@/common/js/common.js'  //先引入文件commonObj.GetDepartment(function(d){  console.log(d)})
26050edfda1e029550d2422fc31706b3.png

第二种:

common.js:

export async function GetDepartment(fn){    var a =await axios.post('/api/common/getDepartment');    return a;  };

所需的vue页:

import {GetDepartment} from '@/common/js/common.js' //先引入文件  解构GetDepartment().then(d=>{  console.log(d);});
792a50ee9c79dc6f4dae6d00b407d984.png

其他方法:https://www.jianshu.com/p/9aa2f6c379dd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值