1. 打開(kāi)index.html
<!-- 引入JS -->
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
?2. 獲取IP?
let IP =?returnCitySN["cip"];
localStorage.setItem('ip',IP);文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-564791.html
?完整代碼:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-564791.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
...省略其他代碼
<!-- 關(guān)鍵點(diǎn)1:引入JS -->
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
</head>
<body>
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script>
//這里是關(guān)鍵點(diǎn)2: 獲取用戶真實(shí)IP地址(外網(wǎng)ip) 并存儲(chǔ)在本地
// document.write(returnCitySN["cip"]+','+returnCitySN["cname"])
localStorage.setItem('ip',returnCitySN["cip"])
</script>
</body>
</html>
到了這里,關(guān)于【vue】前端獲取用戶真實(shí)IP地址 (外網(wǎng)IP地址)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!