项目搭建用vue,记录一下vue神坑,以备后续项目提防。vue
1.项目中没有用到的图片,vue不会打包到img。这样给后端的img路径在展现时候就会404。解决方案:1.在项目中隐式加图片打包到img中。2.使用vue的copywebpackpluginf复制到一个目录下。webpack
2.使用vue页面之间跳转传值,刷新跳转页面会丢掉上一页传过来的值。目前解决办法是存到session 中或者拼接到url中。ios
3.axios添加统一请求头方式:
axios.defaults.headers.common['请求头名称']='请求头中传的参数'web
在路由跳转的时候加变量的请求头:ajax
例如在页面加载时候,生成一个惟一的时间戳,在index.js文件添加:axios
router.beforeEach((to,from,next)=>{后端
sessionStorage.setItem('time',(new Date()).getTime());session
next()post
});url
给全部axios请求头添加pama-no参数
export const ajaxPostRequest = (url,data)=>axios.post(url,data,{
headers:{
'pama-no' : sessionStorage.getItem('time')
}
})
.then(res=>{
})
.catch(res=>{
})
4.