vue项目:
在 public 文件夹中 index.html 加如下代码:(注:使用的搜狐接口)
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
sessionStorage.setItem('ip', returnCitySN["cip"])
</script>
<script src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
console.log(returnCitySN["cip"] + ',' + returnCitySN["cname"])
var value = returnCitySN["cip"] || '';
var name = 'o-cip';
if (typeof value === typeof {}) value = JSON.stringify(value);
window.localStorage.setItem(name, value);
var value1 = returnCitySN["cname"] || '';
var name1 = 'o-cname';
if (typeof value1 === typeof {}) value1 = JSON.stringify(value1);
window.localStorage.setItem(name1, value1)
window.initNECaptcha = initNECaptcha
</script>
在需要传ip地址的地方获取就可以了
this.lastIp = sessionStorage.getItem('ip')
网友评论