1.基础
1.1.安装
npm install vue-router@3.6.5
1.2.引入
import VueRouter from "vue-router"
1.3.注册
Vue.use(VueRouter)
1.4.创建
const router = new VueRouter(
{
routes: [
{path:'/page1', page1},
{path:'/page2', page2}
]
}
)
1.5.引用
new Vue({
render: h => h(App),
router
}).$mount('#app')
1.6.例子
<a href="#/page1">page1</a>
<a href="#/page2">page2</a>
<router-link to="/page1">page1</router-link>
<div style=" width: 1200px; height: 200px;">
<router-view></router-view>
</div>