需求:t通过外部资源获取获取ip地址,
<script src="[http://pv.sohu.com/cityjson?ie=utf-8](http://pv.sohu.com/cityjson?ie=utf-8)" ></script>
<script type="text/javascript">
document.write('IP:'+returnCitySN.cip+'<br>城市:'+returnCitySN.cname);
</script>
在vue组件中使用
通过webpack-require-http,就可以这样
require(['http://pv.sohu.com/cityjson?ie=utf-8'], () => {
setTimeout(() => {
if (returnCitySN) {
console.log(returnCitySN)
} else {
}
}, 1500)
})
安装
npm install webpack-require-http
webpack.base.config.js配置
{
...
entry:{
...
},
output:{
...
},
externals:[
require('webpack-require-http')
]
...
}