在使用 vue-cli3 build的時候,使用非子目錄需要在 vue.config.js 中添加如下代碼:
module.exports = { baseUrl: process.env.NODE_ENV === 'production' ? '/dist/' : '/',}但是build完后,放在nginx服務下,會看到如下報錯,頁面也顯示 no-script 的內容
[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
網上找了很多,并沒有找到答案。后來發現 vue-router 是用了 history 模式,但是 nginx 并沒有添加相應的配置便會出現這個問題。所以,如下解決方案:
1.變更生產環境配置,使得支持 history 模式。這里只需要修改 nginx 的配置,把 404 指向 index.html 即可。
2.不在使用history模式
總結
以上所述是小編給大家介紹的vue-cli3 使用子目錄部署問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!
新聞熱點
疑難解答
圖片精選