vue配置接口url

接上一篇“vue配置axois多环境跨域访问”,aoxis在请求是要有url的,这里写ur的配置

为了项目的需要,可以在src的common文件夹下新建api文件夹,在文件夹下新建index.js,在这里写配置文件

 

import { xmmc } from './xmmc.js' //导入项目名称
import commonWea from './commonWea/index.js' //导入类别url
import { API_SERVER } from '../config'


export default {
    baseURL: API_SERVER.default, //基本url
    imgUrl: "/" + xmmc + "/filedownload?image=",

    //******************************** */低空气象接口******************
    commonWea,

}

其中 coomonWea目录是根据项目的需要,将url根据类别进行分类,当url太多时,方便管理

import { xmmc } from '../xmmc.js' //导入类别url

export default {
    // 获取实况的最新消息
    getCmaImg: "/" + xmmc + "/gis/getColorMap.do"
}

// WEBPACK FOOTER  路径url 配置 //
// ./src/common/commonWea/index.js

xmmc是接口的根目录地址

/*
 * @Author: c项目名称配置,用以配置接口url的完整地址
 * @Date: 2019-11-4 09:52:24 
 * @Last Modified by: c
 * @Last Modified time: 2019-11-04 09:54:08
 */
const xmmc = "cccc";
export {
    xmmc
}

项目组整体路径截图如下:

vue配置接口url_第1张图片

项目中调用,

import api from '@/common/api/index.js'  //引入api地址
var url = api.commonWea.getCmaImg;//请求url

 

你可能感兴趣的:(vue小白炼成记,vue3)