vue項目之index.html如何引入JS文件
更新時間:2022年12月07日 11:46:51 作者:牛先森家的牛奶
這篇文章主要介紹了vue項目之index.html如何引入JS文件問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
vue index.html引入JS文件
注意路徑的寫法
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> -->
<link rel="icon" href="<%= BASE_URL %>favicon.ico" rel="external nofollow" rel="external nofollow" >
<title><%= webpackConfig.name %></title>
<!-- 前端監(jiān)控 -->
<script src="/lib/monitor/web-report-default.min.js"></script>
<script>
Performance({
domain: 'https://frontend-monitor.com/api/v1/report/web',
add:{
appId:'<%= htmlWebpackPlugin.options.monitorId %>' // 生成的其應(yīng)用的appid
}
})
</script>
<!-- 友盟 -->
<script type="text/javascript" src="https://s9.#/z_stat.php?id=1279953853&web_id=1279953853"></script>
<script>
document.querySelector('a[title]').style.display = 'none'
</script>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
注意點
<script src="/lib/monitor/web-report-default.min.js"></script>
打包的文件

index.html引入js文件失效的解決
在static文件夾下寫了一個config.js配置文件,但是引入后報錯,提示沒找到該文件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico" rel="external nofollow" rel="external nofollow" >
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="main"></div>
<!-- built files will be auto injected -->
<script type="text/javascript" src="./static/config.js"></script>
<script type="text/javascript" src="./static/leader-line.min.js"></script>
</body>
</html>解決辦法
引入時,將 "./" 去掉即可

總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue-cli創(chuàng)建項目從單頁面到多頁面的方法
本篇文章主要介紹了Vue-cli創(chuàng)建項目從單頁面到多頁面的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09
解決vue語法會有延遲加載顯現(xiàn){{xxx}}的問題
今天小編就為大家分享一篇解決vue語法會有延遲加載顯現(xiàn){{xxx}}的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue實現(xiàn)給div綁定keyup的enter事件
這篇文章主要介紹了vue實現(xiàn)給div綁定keyup的enter事件,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
關(guān)于vue路由監(jiān)聽事件跳轉(zhuǎn)的問題
這篇文章主要介紹了關(guān)于vue路由監(jiān)聽事件跳轉(zhuǎn)的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08

