一、vue的编译模式

(1)路由配置信息

 

 

 1 //eg1:
 2 const MSite = resolve => require.ensure([], () =>resolve(require(['myComponent.vue'])) 
 3 
 4 //eg2  需要syntax-dynamic-import插件
 5 const MSite = () => import('../pages/MSite/MSite.vue') //异步加载
 6 //import MSite from '../pages/MSite/MSite.vue' 同步加载
 7 
 8 // 声明使用插件
 9 Vue.use(VueRouter)
10 export default new VueRouter({
11   routes: [
12     {      
13         path: '/msite',
14         // 返回路由组件的函数, 只有执行此函数才会加载路由组件, 这个函数在请求对应的路由路径时才会执行
15         component: MSite,   

Vue 组件异步加载(懒加载)   Vue 组件异步加载(懒加载)

 

(2)组件或第三方库

A、懒加载组件

 1 export default {
 2     beforeCreate () {
 3         import('dayjs').then(module => {
 4             this.dayjs = module;
 5         });
 6     },
 7     data () {
 8         return {
 9             dayjs: null
10         }
11     }

 

 

B、同步加载组件

 

import utiljs from 'utiljs'
export default {
      data () {},    
      mounted () {}
}

相关文章:

  • 2021-12-17
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
猜你喜欢
  • 2021-10-25
  • 2022-12-23
  • 2021-08-28
  • 2021-11-27
  • 2022-12-23
  • 2021-11-26
相关资源
相似解决方案