uniapp获取ip的方法起因是H5调取VX支fu,后台非让我获取ip
首先新建一个indexl文件
[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title> <%= htmlWebpackPlugin.options.title %> </title>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
})
</script>
<link rel="stylesheet" href="<%= htmlWebpackPlugin.options.baseUrl %>static/index.css" /> <!-- 引入外部js -->
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
// 获取ip console.log(returnCitySN["cip"]+','+returnCitySN["cname"])
</script>
</head>
<body> <noscript> <strong>Please enable JavaScript to continue.</strong> </noscript>
<div id="app"></div> <!-- built files will be auto injected -->
</body>
</html>
然后打开manifest.json
[JavaScript] 纯文本查看 复制代码 "h5" : {
"devServer" : {
"port" : 8000,
"disableHostCheck" : true,
}, //这里引入html
"template" : "index.html",
"optimization" : {
"treeShaking" : {
"enable" : true
}
}
}
然后你就会发现,可以了!
|