vue入门之--路由.docx

时间:2020-03-26 13:37:43
【文件属性】:
文件名称:vue入门之--路由.docx
文件大小:16KB
文件格式:DOCX
更新时间:2020-03-26 13:37:43
vue 路由 1、安装 npm install vue-router --save 2、在main.js里引入 import router from './router' 3、配置路由 ①创建组建引入组建 import Center from '@/views/Center' ②定义路由 const routes = [{ path: '/center', component: Center }, ] ③实例化VueRouter const router = new VueRouter({ routes }) ④挂载 new Vue({ router, render: h => h(App) }).$mount('#app') ⑤根组件的模板里放上 ⑥根据按钮跳转时 首页 编程式导航路由跳转 this.$router.push({ path: 'home'}) 4.动态路由传值 const routes = [ /*动态路径参数以冒号开头*/ { path: '/home/:id', component: Home }, ] /*跳转时拼接路由*/ 首页 在对应界面获取动态路由的值 this.$route.params get方法获取动态路由的值 首页 在对应界面获取动态路由的值 this.$route.query

网友评论