在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue-router 路由懶加載

vue-router 路由懶加載

import Vue from 'vue'
import Router from 'vue-router'

const Daily = () => import('../components/Daily.vue')
const Cosplay = () => import('../components/Cosplay.vue')
const Draw = () => import('../components/Draw.vue')

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/daily',
      name: 'daily',
      component: Daily
    },
    {
      path: '/cos',
      name: 'cos',
      component: Cosplay
    },
    {
      path: '/sifu',
      name: 'sifu',
      component: Cosplay
    },
    {
      path: '/draw',
      name: 'draw',
      component: Draw
    },
    {
      path: '/',
      redirect: '/cos'
    }
  ]
})

按照 vue-router 官方文檔中的做法配置了路由懶加載,但是運(yùn)行時卻報錯:

Vue warn: Failed to mount component: template or render function not defined.

想問問大家是怎么配置路由懶加載的。

回答
編輯回答
忘了我

.babelrc

{

"plugins": ["syntax-dynamic-import"]

}

2017年3月23日 05:00
編輯回答
兮顏

找到問題了,在 vue-router 2.x 中,要這么寫:

const foo= () => import('../components/foo.vue').then(m => m.default)

vue-router 3.x 中,可以這么寫:

const foo= () => import('../components/foo.vue')
2018年9月12日 09:52
編輯回答
眼雜

路由配置沒有問題,看錯的應(yīng)該是你vue文件書寫錯誤或者是es轉(zhuǎn)碼錯誤,多半是前者

2017年11月5日 03:51
編輯回答
萌小萌

那你之前寫的不就對嗎

2018年7月7日 18:33