keep fool,keep hungry~

  当然笔记的记录还是不能断的,keeping~

相关链接

  1. Vue_VueResource
  2. 详解JS函数柯里化
  3. Vue.js简单集成ACE代码编辑器
  4. 基础图类Basic Plots 15 - 和弦图Chord Chart
  5. JS——DOM操作(childNodes、nodeType和children区别与用法)
  6. js高阶函数应用—函数柯里化和反柯里化
  7. JS高级函数——–map/reduce
  8. 简单总结ES6的Map
  9. Serverless初探
  10. 当我们聊Serverless时你应该知道这些
  11. 花了 1000G,我终于弄清楚了 Serverless 是什么(上):什么是 Serverless 架构?
  12. js中的广度优先遍历(BFS)和深度优先遍历(DFS)
  13. BFS,DFS 算法原理及js实现
  14. SVG路径PATH
  15. d3 cluster
  16. d3js layout 深入理解
  17. D3.js中Radial Cluster Dendrogram详解
  18. D3.js从入门到“放弃”指南
  19. 灰信网
  20. d3可视化实战00:d3的使用心得和学习资料汇总
  21. 夜舞暗澜_3ea2
  22. 嘿,不要给 async 函数写那么多 try/catch 了
  23. 一个合格的中级前端工程师必须要掌握的 28 个 JavaScript 技巧
  24. d3 画曲线
  25. 深度掌握SVG路径path的贝塞尔曲线指令
  26. D3.js中的Chord Diagram详解
  27. 实施微前端的六种方式
  28. 深入理解 JavaScript 中的 class

axios拦截器

相关资料

  1. Axios的拦截器原理以及请求等待重发的实现
  2. axios 官网

分类

 请求拦截器、响应拦截器

// 请求
axios.interceptors.request.use(config => {
    // 在发起请求请做一些业务处理
    return config
  }, error => {
    // 对请求失败做处理
    return Promise.reject(error)
  })
// 响应
axios.interceptors.response.use(response => {
    // 对响应数据做处理
    return response
  }, error => {
    // 对响应错误做处理
    return Promise.reject(error)
  })

使用

 默认在 main.js 中进行配置

  axios.interceptors.request.use(config => {
    if (config.method === 'post') {
      config.data = qs.stringify(config.data)
    }
    return config
  })

 在 src 文件夹内创建 config 文件夹,并在新建文件夹内创建 index.js 文件

// config/index.js
const env = process.env.NODE_ENV

const production = { // 生产地址
  commonPath: ''
}

const development = { // 开发地址
  commonPath: ''
}

const location = env === 'production' ? production : development
export default location

 在 src 文件夹内创建 server 文件夹,并在新建文件夹内创建 index.js request.js 两个文件

// sever/request.js
import axios from 'axios' // 引入axios
import conf from '../config/index' // 引入请求地址

const hostFilter = hostType => {
  switch (hostType) {
    case 'common':
      return conf.commonPath // 配置请求地址
  }
}

export default {
  post: (hostType, url, data, error, option) =>
    axios.post(hostFilter(hostType) + url, data, option) // 配置请求
      .then(response => {
        // console.log(response.data)
        return response.data
      })
      .catch(err => {
        error ? error(err) : console.log(err)
      }),
  url (hostType, path) { return hostFilter(hostType) + path }
}
// index.js
import http from './request' // 引入http

export const name = data => http.post('','', data)
//        调取接口名              请求地址 请求路径

开发规范(想到什么就记点什么)

 可以考虑与 ES6 组合优化。

特定变量

  const MAX_INPUT_LENGTH = 8; // 对比数进行命名,明确其对应的是什么
  if (value.length < MAX_INPUT_LENGTH) {
    ....
  }


笔记      Learning Notes Work Notes vue

本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!