开发过程中,可配置想,另外使用一个js文件作为配置文件。比如url
编写接口配置文件
项目src目录下建立config.js
,然后打开编写如下代码。
const BASEURL = "https://www.aa/cc/"
const URL = {
getIndex:BASEURL+'getIndex',
getMessage:BASEURL+'getMessage'
}
module.exports = URL
编写好后,我们可以直接在要使用的文件中用import的形式引入。
import url from './config.js'
引入后就可以直接使用了。
axios({
url: url.getIndex,
method: 'get',
})