一切福田,不離方寸,從心而覓,感無不通。

npm ERR! Unexpected end of JSON input while parsing near

You are trying to create a new angular, react, vue app, and you end up with an error message saying: npm ERR! Unexpected end of JSON input while parsing near There’s a high chance that your npm cache been damaged. Try:

  If you are a windows user, try deleting all files in this folder:

  Then…

  If that doesn’t work, try updating to the lastest (understand the risks)

  I hope this helps!   from:https://dev.to/rishiabee/npm-err-unexpected-end-of-json-input-while-parsing-near-743

龙生   22 Jan 2021
View Details

Vue 魔法师 —— 将 API “类化”

前言 【类】和【接口】是 JavaScript 未来的方向,我们的 API 调用也将如此,朝着这个方向和业务模块同步分类、同步升级。本文讲的正是 —— Vue 魔法师,如何将 API “类化”? 万物皆模块,万物可归类。闲言少叙,直接正题。 分类 API 环境: Vue2+ 或 Vue3+ 咱这里直接 VueCLI 迅速快捷构建

得到如下目录

  然后新建文件 api.js 如下,

  基础类 API 我们先创建一个基础类如下:

  baseUrl:设置请求根路径; resource:来源; getUrl:获取链接函数,包含 baseUrl、resource、id; handleErrors:处理错误函数; 只读类 API 然后,我们再创建一个子类:包含 fetch、get 只读方法。

  fetch:获取数据; get:通过 id 获取数据; 写入类 API 接着,我们再创建一个包含可读写方法的子类:post、put、delete

  post:创建数据; put:更新数据; delete:删除数据; 继承 让我们看看两个简单的继承示例:

 

  【UsersApiService 类】继承了只读类 API —— ReadOnlyApiService,可以使用 fetch、get 两种方法。而 【PostsApiService 类】继承了读写类 API —— ModelApiService,可以使用 fetch、get、post、put、delete 五种方法。 我们也可以根据业务来写继承 API 类:

  导出 我们在 api.js 导出这些 […]

龙生   22 Jan 2021
View Details