每天坐在教室里,但眼神总是看着窗外的风景,不知不觉的默默发呆。我一直急速前行,穿梭于人人之间。试图借应接不暇的风景让我褪去对你的思念。
本文实例为大家分享了Vue异步加载about组件的具体代码,供大家参考,具体内容如下
异步加载about组件
about.js
Vue.component('about', {template: '<div>ABOUT PAGE</div>'});
html代码:
<div id="app"> <router-link to="/home">/home</router-link> <router-link to="/about">/about</router-link> <router-view></router-view> </div> <script src="static/js/vue.min.js"></script> <script src="static/js/vue-router.js"></script> <script> function load (componentName, path) { return new Promise(function (resolve, reject){ var script = document.createElement('script'); script.src = path; script.async = true; script.onload = function () { var component = Vue.component(componentName); if (component) { resolve(component); } else { reject(); } } document.body.appendChild(script); }); } var router = new VueRouter({ routes: [{ path: '/', redirect: '/home' }, { path: '/home', component: { template: '<div>HOME PAGE</div>' } },{ path: '/about', component: function (resolve, reject) { load('about', 'static/js/business/about.js').then(resolve, reject); } }] }); var app = new Vue({ el: '#app', router: router }); </script>
到此这篇关于Vue异步加载about组件就介绍到这了。人的美不在外貌、 衣服和发式,而在于它的本身,在于他的心。要是人没有内心的美,我们会常常厌恶他漂亮的外表。更多相关Vue异步加载about组件内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!