npm i vue-router
<script src="node_modules/vue-router/dist/vue-router.min.js" type="text/javascript" charset="utf-8"></script>
externals: {
// jquery: ‘jQuery‘,
// jquery: ‘$‘,//这两种方式都可以
// VueRouter 这个值为vue-router 导出的接口对象,不知道的查
vue: ‘Vue‘,
‘vue-router‘: ‘VueRouter‘
},
import VueRouter from ‘vue-router‘
import Foo from ‘./components/Foo.vue‘
import Bar from ‘./components/Bar.vue‘
// 这里直接默认导出new出来的router实例
export default new VueRouter({
routes: [{
path: ‘/foo‘,
component: Foo
},
{
path: ‘/bar‘,
component: Bar
}
]
})
import Vue from ‘vue‘
import App from ‘./App.vue‘
import router from ‘./routers‘
// import ‘./components/main.css‘//可以这样引入css文件,并且支持热更新
new Vue({
el: ‘#app‘,
template: ‘<App />‘,
router,
components: {
App
}
})
/* new Vue({
template: ‘<App />‘,
components: {
App
}
}).$mount(‘#app‘) */
<template>
<div id="app">
<h1 class="A1">已经是热更新了,呵呵呵</h1>
<ul>
<li><a href="#/foo">foo</a></li>
<li><a href="#/bar">bar</a></li>
</ul>
<router-view></router-view>
</div>
</template>
原文:https://www.cnblogs.com/191080438qq/p/14977851.html