时间:2021-07-01 10:21:17 帮助过:32人阅读
const Foo : {template: '<p> this is foo </p> const Bar : {template: '<p> this is bar </p> .....
2、定义路由
const routes: [ {path: '/foo', component: Foo}, {path: '/bar', component: Bar} ]
3、创建路由实例,传入定义路由的配置
const router = new VueRouter({ routes: routes })
4、创建挂载根实例
const app = new Vue({ router: router }).$mount('#app')
HTML
<!--外部链接--><script src="https://unpkg.com/vue/dist/vue.js"></script><script src="https://unpkg.com/vue-router/dist/vue-router.js"></script><p id="app"> <h1>Hello</h1> <p> <router-link to="/foo">Go to Foo</router-link> <router-link to="/bar">Go to Bar</router-link> </p> <router-view></router-view></p>
以上就是vue中创建路由的几个步骤 的详细内容,更多请关注Gxl网其它相关文章!