亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue2和vue3部署到服務(wù)器子目錄為空白頁問題及解決

 更新時(shí)間:2024年07月05日 14:33:29   作者:我是劉拾貳  
這篇文章主要介紹了vue2和vue3部署到服務(wù)器子目錄為空白頁問題及解決,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

問題

今天遇到vue項(xiàng)目部署到服務(wù)器默認(rèn)hash沒問題但是hhistory為空白的問題。

研究了一下找到了答案記錄一下

vue項(xiàng)目history模式部署在子路徑

項(xiàng)目打包后默認(rèn)只能部署在服務(wù)器根路徑,如果想 http://www.xxx.com/demo/ 這種形式

vue3+vite配置方法

  • vite.config.ts 中配置:
export default defineConfig(({ command }) => {
    return {
        // 在這里增加 base 寫子路徑
        base: '/demo/',  
        resolve: { /*......省略*/ }

    };
});
  • 然后在router 中增加:
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'


const router = createRouter({
   // 給 createWebHistory 方法傳參數(shù)配置子路徑
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
  ]
})

export default router

vue2+cli配置方法

vue.config.ts 中配置:

// vue.config.js
const vueConfig = {
// 在這里增加 publicPath寫子路徑
 publicPath:'/demo/'

 //......忽略其他
}

module.exports = vueConfig

然后在router 中增加:

export default new Router({
  mode: 'history',
  // 增加bese信息 
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes
})

vue項(xiàng)目hash模式部署在任意路徑

vue3+vite配置方法

  • vite.config.ts 中的 base 配置值為空或者 ./
// ......省略其它代碼
export default defineConfig(({ command }) => {
    return {
        base: '',
        //base: './',
    };
});
  • src/router/index.ts 中路由 history 模式改為 hash 模式:
import { createRouter, createWebHashHistory } from 'vue-router';

// ......省略其它代碼
const router = createRouter({
    routes,
    history: createWebHashHistory()
});

vue2+vueCli配置方法

  • vue.config.ts 中配置為空或者 ./
// vue.config.js
const vueConfig = {
// 在這里增加 publicPath寫子路徑
 publicPath:'./'

 //......忽略其他
}

module.exports = vueConfig

然后在router 中設(shè)置hash:

export default new Router({
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes
})

總結(jié)

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論