项目中有有一个地区接口,服务器原因请求速度很慢很慢,于是考虑将地区接口的数据设置为本地的json文件。大大提升请求速度

一、首先创建一个json文件,将数据放进去,一定要确保格式正确我的是这样的,把json文件放在static文件夹下,

                     

二、像使用axios一样去调用json文件,因为我的axios配置的时候设置的是$ajax = axios

Vue.prototype.$ajax = axios;

所以调用json文件如下操作,其中注意我用的是/绝对路径,不用写什么localhost,最后部署到服务器上还是要这个绝对路径,

this.$ajax.get('/static/mock.json').then((res) => {
   this.areaData=res.data      //res.data可根据你的数据格式来,看需求
   console.log(this.areaData) //打印看看数据吧
})

然后就可以肆无忌惮的用数据了。

给大哥点点关注!

GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
2134cb94 * change NLOHMANN_JSON_FROM_WITH_DEFAULT to let NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT work with an empty JSON instance * fix ci_static_analysis_clang (ci_clang_tidy) * change NLOHMANN_JSON_FROM_WITH_DEFAULT to let NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT work with an empty JSON instance 9 天前
6057b31d * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * Use ubuntu-latest image to run Valgrind (#4575) * :wrench: use Clang image to run valgrind * :wrench: use Clang image to run valgrind * :wrench: use Clang image to run valgrind * :wrench: use Ubuntu image to run valgrind * Use Clang image to run iwyu (#4574) * :wrench: use Clang image to run iwyu * :wrench: use Clang image to run iwyu * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :art: format code * :hammer: clean up 10 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐