JavaScript/vue.js/error:修订间差异
来自康健生活
| 第75行: | 第75行: | ||
at XMLHttpRequest.l.onerror (spread.js:25)</pre> | at XMLHttpRequest.l.onerror (spread.js:25)</pre> | ||
:* 这个问题源于 我设置的 <code>axios.defaults.baseURL='http://localhost:3000';</code>,网络请求地址指向了开发机自己,当用其他机器测试时请求地址指向测试机地址,所以抛错。 | :* 这个问题源于 我设置的 <code>axios.defaults.baseURL='http://localhost:3000';</code>,网络请求地址指向了开发机自己,当用其他机器测试时请求地址指向测试机地址,所以抛错。 | ||
:* 解决办法分三步 | |||
:* {{hc|package.json|<syntaxhighlight lang="javascript"> | |||
"sshbuild": "export NODE_ENV=production HOST=152.32.132.166 && webpack --mode production --config webpack.config.js", | |||
</syntaxhighlight>}} | |||
:* {{hc|webpack.config.js|<syntaxhighlight lang="javascript"> | |||
const AXIOSHOST = process.env.HOST; | |||
/** | |||
* 配置全局常量 | |||
*/ | |||
new webpack.DefinePlugin({ | |||
'axios_host':JSON.stringify(AXIOSHOST), | |||
}), | |||
</syntaxhighlight>}} | |||
:* {{hc|router/index.js|<syntaxhighlight lang="javascript"> | |||
axios.defaults.baseURL='http://'+axios_host+':3000'; | |||
</syntaxhighlight>}} | |||