1. 打开index.html

<!-- 引入JS -->

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>

 2. 获取IP 

let IP = returnCitySN["cip"];

localStorage.setItem('ip',IP);

 完整代码:

<!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>

        ...省略其他代码

        <!-- 关键点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> 
             //这里是关键点2: 获取用户真实IP地址(外网ip) 并存储在本地
            // document.write(returnCitySN["cip"]+','+returnCitySN["cname"]) 
            localStorage.setItem('ip',returnCitySN["cip"])
        </script>
    </body>

</html>

Logo

前往低代码交流专区

更多推荐