vue打包頁面空白(最完美的解決辦法)
阿新 • • 發佈:2018-11-10
vue打包頁面空白,什麼都不顯示(解決)
當打完包的時候,可以看到它提示一句話
Tip: built files are meant to be served over an HTTP server.
Opening index.html over file:// won’t work.
這句話的意思就是打包的檔案必須要通過服務啟動,,直接開啟無效。看到這句話就蒙了,不知道怎麼改,就去百度了,試了各種方法還是都行不通,找了許久終於找到一個能行的了。
、
這段操作共需要改三部分
-
找到config資料夾下index.js
build: { // Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: 'static', assetsPublicPath: './', //**這裡就是要改的地方,原來是'/',改為'./'** /** * Source Maps */
-
找到build資料夾下utils.js
// Extract CSS when that option is specified // (which is the case during production build) if (options.extract) { return ExtractTextPlugin.extract({ use: loaders, fallback: 'vue-style-loader', publicPath:'../../' //新加入此行程式碼 }) } else { return ['vue-style-loader'].concat(loaders) } }
-
找到router下面的index.js
mode: 'hash', // 把mode設定未hash