1.封装axios

vue常见知识点

假如我们要上传图片:

this.$http({
    url: '/common/upload',
    method: 'post',
    data: formdata,
    headers: { 'Content-Type': 'multipart/addAndEditForm-data' },
}).then((url) => {
    this.$refs.md.$img2Url(pos, url);
})

除开图片,我们基本都是json格式,所以我们可以配置个全局的:

axios.defaults.headers['Content-Type'] = 'application/json';

相当于:

axios.defaults.headers.get['Content-Type'] = 'application/json'和
axios.defaults.headers.post['Content-Type'] = 'application/json';

2.export和export defalut的区别

vue常见知识点

 3.封装api

vue常见知识点

vue常见知识点

相关文章:

  • 2021-07-11
  • 2021-12-26
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-04-23
  • 2021-12-19
  • 2021-10-16
猜你喜欢
  • 2021-06-06
  • 2022-02-05
  • 2021-06-01
  • 2022-03-04
  • 2021-12-05
  • 2021-08-11
  • 2021-06-20
相关资源
相似解决方案