vue打包之後,在本地訪問index.html頁面是一片空白,並且控制檯會報錯。
解決辦法
- vue-cli2:首先找到config/index.js文件,將assetPublicPath的路徑改爲“./”
- vue-cli3:在項目的根目錄下創建vue.config.js,並加入以下代碼。
module.exports = {
publicPath: './',
assetsDir: 'static',
parallel: false
}
到了這步如果還是沒有顯示出來,那是因爲你的路由模式的關係,你把你的路由模式改成“hash”就行了
vue中常用的路由模式 :
- hash(#):默認路由模式
- histroy(/)切換路由模式
切換路由模式:
export default new Router({
// 路由模式:hash(默認),history模式
mode: 'hash',
// 修改路由高亮樣式,默認值爲'router-link-active'
linkActiveClass: 'active'
//路由規則
routes:[
{
path:'/',
name:'index',
component:'Index'
}
],
})