公司需求: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>
在想獲取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))