axios中止单个网络请求
const CancelToken = axios.CancelToken
config.cancelToken = new CancelToken((cancel) => {
// 存储并使用cancel
})
axios中止所有的网络请求
- 使用CancelToken
- 在axios的请求拦截中,使用store存储每个请求的cancelToken实例
- 拦截路由,调用cancelToken()方法终止请求
几种控制页面隐藏与显示的方式
opacity
- 控制透明度
- 父级及子级事件生效
- 子级根据最小的opacity生效
v-show
- 本质使用display: none|block
- 不占位,元素节点存在
- 父级优先级
v-if
- 不占位
- 元素从页面中去除
监听路由
使用watch
watch: {
$route(to,from) {
//
}
}
watch: {
'$route': 'method'
}
watch: {
$route: {
handler: function(to,from) {
//
},
deep: true
}
}
vue-router的声明周期钩子
beforeRouteEnter(to,from,next) {
//
}
beforeRouteUpdate(to,from,next) {
//
}
beforeRouteLeave(to,from,next) {
//
}
全局路由拦截
router.beforeEach((to,from,next) => {
//
})
router.beforeResolve((to,from,next) => {
//
})
router.afterEach((to,from) => {
//
})
路由独享守卫
{
path: xxx,
name: xxx,
component: xxx,
beforeEnter: (to,from,next) => {
//
}
}