zoukankan      html  css  js  c++  java
  • Vue之axios

    1、axios 的get方式

      

    1  created() {
    2                 axios.get('https://showme.myhope365.com/api/shop/shopGoods/open/banner/list'
    3                     , {
    4                         headers: { 'X-Requested-With': 'XMLHttpRequest' }
    5                     }).then(res => {
    6                         console.log(res);
    7                     })
    8             }

    2、axios的post方式

    1  created() {
    2                 let parmas = new URLSearchParams();
    3                 parmas.append("pageNum", 1);
    4                 parmas.append("pageSize", 5);
    5                 axios.post('https://showme.myhope365.com/api/shop/shopGoods/open/list', parmas).then(res => {
    6                     console.log(res);
    7                 })
    8             }

     默认是JSON格式。 可以实例化URLSearchParams(). 然后进行使用append()。

    3、axios的文件上传

     1 methods: {
     2                 select(e) {
     3                     console.log(e);
     4                     console.log(e.target.files[0]);
     5                     this.file = e.target.files[0];
     6                 },
     7                 up() {
     8                     console.log("上传");
     9                     const formdata = new FormData();
    10                     formdata.append('file', this.file);
    11                     formdata.append('fileUserForEnum', "DEFAULT")
    12                     axios.post('http://59.111.92.205:13010/api/nos/upload/image', formdata).then(res => {
    13                         console.log(res);
    14                     })
    15                 }
    16             }

     实例化 FormData() ,formdata.append('file', this.file);   formdata.append('fileUserForEnum', "DEFAULT")

  • 相关阅读:
    正则里的.*?
    无边框缩放
    平台 测试笔记
    eclipse快捷键
    linux笔记
    笔记
    wamp、wordpress
    java-selenium
    html/css笔记
    selenium2——ruby
  • 原文地址:https://www.cnblogs.com/qianqiang0703/p/13635875.html
Copyright © 2011-2022 走看看