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){  }
}

3.vuex及vue-router常用方法示意:

this.$store.dispatch('XXX');

this.$route.path/this.$route.params

posted @ 2018-09-03 00:04  站住,野猪佩奇  阅读(745)  评论(0编辑  收藏  举报