1. 程式人生 > >vue 仿新聞項目筆記

vue 仿新聞項目筆記

header 過濾 ade mode 發送 url int prototype ESS

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

vue 仿新聞項目筆記