• vue中axios请求数据


     引入文件

    <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>

      代码块:

      1、get请求:

      

    复制代码
     1             var params = {
     2                 locale: 1,
     3             };
     4             // 向具有指定ID的用户发出请求
     5             axios.get('/user?ID=12345')
     6                 .then(function (response) {
     7                     console.log(response);
     8                 })
     9                 .catch(function (error) {
    10                     console.log(error);
    11                 });
    12 
    13 
    14             // 也可以通过 params 对象传递参数
    15             axios.get('/user',{params:params}).then(function (res) {
    16                 console.log(res)
    17             }).catch(function (err) {
    18                 console.log(err);
    19             })    

     2、post请求:

      

    复制代码
     1             axios.post('/url', {
     2                 sex: '1',
     3                 age: '2'
     4             })
     5                 .then(function (res) {
     6                     console.log(res);
     7                 })
     8                 .catch(function (err) {
     9                     console.log(err);
    10                 });
    复制代码

    3、多个并发请求:

      

    复制代码
     1             function getOne() {
     2                 return $http.get('/url/1');
     3             }
     4 
     5             function getSecond() {
     6                 return $http.get('/url/2/secondUrl');
     7             }
     8 
     9             axios.all([getOne(), getSecond()])
    10                 .then(axios.spread(function (success, perms) {
    11                     //两个请求现已完成
    12                 }));
    正道的光终将来临,当太阳升起的时候,光芒总会普照大地温暖人间。些许的阴霾也终会有被阳光洒满的一天
  • 相关阅读:
    【MySQL】GTID小结
    MongoDB副本集--Secondary节点实例恢复
    【linux】glibc升级
    001.LVM简介
    008.FTP单独虚拟用户
    007.FTP虚拟用户访问
    006.FTP用户访问控制配置
    005.FTP本地用户访问
    004.FTP匿名用户访问
    003.FTP客户端连接
  • 原文地址:https://www.cnblogs.com/sjruxe/p/13384068.html
Copyright © 2020-2023  润新知