公司需求:vue中获取客户端IP地址
方法1:从网上找了一个,如下链接,根本不行,获取不了。
https://www.cnblogs.com/cwl1025/p/14248306.html
方法2:可行,链接如下:
https://www.cnblogs.com/cwl1025/p/14248306.html
在index.html中引入
<script src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
js获取ip代码如下
var Ip=returnCitySN['cip']
var cityname=returnCitySN['cname']
localStorage.setItem('Ip', Ip)
console.log(localStorage.getItem('Ip', Ip))
localStorage.setItem('cityname', cityname)
console.log(localStorage.getItem('cityname', cityname))
PS:因为vue是单页,所以可以直接拿来用
其他:动态引入script
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://g.alicdn.com/de/prismplayer/2.8.2/aliplayer-min.js';
document.body.appendChild(script );
网友评论