vue中使用基于客户端的缓存

在写基于express、vuejs博客的小项目过程中,折腾了下在vuejs中怎么使用浏览器缓存请求。

原理是利用vue-resource拦截器interceptor,判断当前请求是否存在localStorage里,有则返回缓存的内容;没有则请求服务器,并在localStorage写入缓存。

用到的依赖包:

详细代码在https://github.com/liukaijv/lnode-blog/tree/master/frontend