開發過程中,可配置想,另外使用一個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',
})