Solve the problem that the interface cannot be accessed after Elcetron is packaged

After packaging, the original interface request addresses all start with app://. If you configure the proxy of devServer during local development, the access interface path will become app://./api/ interface address ( If /api is proxied) there is no problem loading local resource files.

solution

devServer is not used in vue.config.js (if it is really necessary, then according to whether the current development environment configuration uses devServer, axios also needs to be judged)

module.exports = {

publicPath: '/',

devServer: {}

}

Add the following code before instantiation of axios

axios.defaults.baseURL = process.env.VUE_APP_PROXY_TARGET //Set different baseURLs according to environment variables

const instance = axios.create( {// instantiate axios

timeout: httpTimeout, // request timeout

})

Guess you like

Origin blog.csdn.net/CSDN_33901573/article/details/129556615