Vue路由传值
<router-link :to="{name:'path',query:{id:44}}"></router-link>
路由接收值!
this.$route.query.id
Vue编程导航
this.$router.go(-1)前进后退
this.$router.push() 直接跳到某页面 可以传字符串或对象{name:'',query:{}}
重定向404处理
路由配置{path:'/',redirect:'/home'}
{path:'*',component:''}写在规则最后
多视图,多个坑位,这时候要用components为多个路由出口配置组件,路由出口没name属性时,用default代表
//html
<router-view name="header"></router-view>
<router-view ></router-view>
//js
import header from './header'
import body from './body'
new Router({
routes:[
{path:'/',components:{
header:header,
default:body
}
}
]
})
嵌套路由
注意点 嵌套路由子路由path配置时前面加/就变成绝对路径 不应该加
{
path:'/',
name:'home',
component:home,
children:[
{path:'oumei',name:'oumei'},
{path:'cuo',name:'guo'}
]
}
axios 使用
axios.defaults.baseURL='' //配置全局路径
this.$axios.get('/api',{header:{},params:{}}//params传参数
this.$axios.post('/api',{},{})