1、/public/ep.js
window.endpoints={
api:'http://localhost:8080/api/v1'
}
2、頁面入口index.html
? ? ? ? 在head中引入js文件文章來源:http://www.zghlxwxcb.cn/news/detail-607732.html
<head>
....
<script type="module" src="/ep.js"></script>
....
</head>
3、其他頁面使用文章來源地址http://www.zghlxwxcb.cn/news/detail-607732.html
<script setup>
const api = window.endpoints.api
</script>
到了這里,關(guān)于vue3+vite+js 引用public文件夾中js文件的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!