vue-cli4中使用Vue.use(VueRouter)报错问题

router/index.js中

vue-cli2中还是使用的import Vue  from 'vue',Vue.use也没有问题

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    }
  ]
})

vue-cli4中不能直接import Vue from 'vue'

import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router

 

posted @ 2021-07-21 15:14  久不见冰蓝  阅读(3014)  评论(0)    收藏  举报