异步组件?

2018-06-18  本文已影响12人  _____西班木有蛀牙

应该是异步组件:

// test/Test.vue
<style src="./Test.css"></style>
<template>
    <div class="test">Test Components</div>
</template>
<script>
export default {
  mounted() {
    import("./Test.js").then(res => {
      res.default();
    });
  }
};
</script>
/*
 *Test.css
 */
.test {
    font-size: 32px;
    color: brown;
}
// Test.js
const initTest = () => {
  console.log('Test init');
}
export default initTest;
// 添加 路由/test
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Test from '@/components/test/Test.vue'

Vue.use(Router)

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

上一篇下一篇

猜你喜欢

热点阅读