uniapp 引入外部js網絡js 獲取ip 更改入口文件

起因是H5調取微信支付,後臺非讓我獲取ip,好死不死我用的偏偏是uniapp,這讓本就是小白的我更加雪上加霜,一度懷疑後臺要把我逼死了。之後想到似乎之前用uniapp引入過一個其他js插件,經過反覆的回憶 懷疑 困頓 迷茫 居然還真就好使了。

首先新建一個indexl文件

<!DOCTYPE html>
<html lang="zh-CN">
	<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

"h5" : {
        "devServer" : {
            "port" : 8000,
            "disableHostCheck" : true,
        },
		// 這裏引入html
		 "template" : "index.html",
		 "optimization" : {
		     "treeShaking" : {
		         "enable" : true
		     }
		 }
    }

然後一打開,哇哦,居然好使了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章