vue 仿新闻项目笔记

1.main.js:

import filters from 'XXX'

Object.keys(filters).forEach(key => Vue.filter(key, filters[key]))  //遍历过滤

const router=new VueRouter({
mode: 'history', //切换路径模式,变成history模式
scrollBehavior: () => ({ y: 0 }), // 滚动条滚动的行为,不加这个默认就会记忆原来滚动条的位置
routes
});

//axios的一些配置
axios.interceptors.request.use();     //配置发送请求的信息

axios.interceptors.response.use();    //配置请求回来的信息

axios.defaults.baseURL = (process.env.NODE_ENV !=='production' ? config.dev.httpUrl:config.build.httpUrl);  //基本请求地址

axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';  //设置请求头

Vue.prototype.$http = axios  //其他页面在使用axios的时候直接  this.$http就可以了

2.监听路由

watch:{
  $route(to,from){  }
}

扫描二维码关注公众号,回复: 3022332 查看本文章

猜你喜欢

转载自www.cnblogs.com/wstmljf/p/9576503.html