安装vue cli npm install @vue/cli -g
一,Vue-router
在index.js中添加路由 1,添加 path: ‘/profile’, name:‘Profile’, component:()=>import(’…/views/Profile’) //导入路径
2,在页面添加 router-link 标签 标签可添加 tag设置 标签样式 如tag=“button”
3,(1)路由传参
在添加路由处path:‘ ‘/user/:id’,’ //添加:id(可随取) 在User页面 添加方法 userId(){ return this.$route.params.id // route属性哪个活跃拿哪个 联系index.js } 还需要 在APP的data(){ //设置数据 return{ userId:list } }
(2)路由query 传参方法 我的 //点击后网页栏 会出现相应数据
在profile的template标签使用{{$route.query.name}} 会把参数显示在页面上
(3)按钮传参数方法 一定要看清 路径
全局导航守卫
router.beforeEach((to, from, next)=>{ //从from跳转到to document.title=to.meta.title next() })
document.title=to.matched[0].meta.title // 有子路由是的写法
路由中添加 meta:{ title:‘首页’ }