vue路由動態增加元件渲染

劉勇大三入門前端發表於2020-12-16
export const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    {
      path: '/', // 必須含有預設 才能動態
      component: {
        render: h => h('div',{},12311)
      }
    }]
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]
import Tex from "./Text";
獲取如下
component: (resolve) => require(["./Text.vue"], resolve), //將元件用require引進來
this.$router.options.routes[0].children.push({
        //插入路由
        name: "list",
        path: "/list",
         component:Tex
      });
      this.$router.addRoutes(this.$router.options.routes); //呼叫addRoutes新增路由
      this.$router.push({
        path: "/list",
      });

相關文章