vue - router.js dynamic registration component

Reference: http://www.pianshen.com/article/6692170109/

 

My needs: a list of pages into the details page, in the list page is loaded, the registration details page. In this way the first time to enter the details page will be faster (because of the introduction js details page in advance), but also will not affect the speed at the time of entering the list page.

 

List js:

Mounted () {
       ****   // Other activities 
      the let = _this the this ;  
      Import ( './Detail.vue').then(module => {   // Note introduction position 
        the let route = {
          path: '/detail',
          name: 'Detail',
          meta: {
            index: 2,
            keepAlive: false,
            title: 'Details page'
          },
          Component: Resolve => the require ([ './ the Detail' ], Resolve) // import component position adjusted, find the words being given vue: Can Not Create Property '_Ctor' ON String 'the Detail'
        }
        _this.$router.options.routes.push(route);
        _this.$router.addRoutes([route]);
      })
}

note:

Guess you like

Origin www.cnblogs.com/linjiangxian/p/12221201.html