zoukankan      html  css  js  c++  java
  • 使用axios请求发送数据

    之前一直没有用成功,今天看了一些博客,学会了使用axios插件

    1.首先就是下载依赖啦

    2.main.js

    import axios from 'axios'
    Vue.prototype.$axios = axios

    axios.defaults.baseURL = 'http://xxx/';
    axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

    3,组件引用 第一种

    var params = new URLSearchParams();   //注意下面的属性必须加引号

    params.append("nickname",this.changeNameVal);
    params.append("sex", this.sexstatus);
    params.append("job", this.changeJobVal);
    params.append("birthday",this.birthday);


    this.$axios.post(
    "index.php/api/User/editPersonalInfo",
    params
    ).then(res=>{}).catch((err)=>{})

    4,组件引用第二种

    组件

    import qs from "qs";

    var params = qs.stringify({

    nickname: this.changeNameVal,
    sex: this.sexstatus,
    //工作
    job: this.changeJobVal,
    birthday: this.birthday,


    })

    this.$axios.post(
    "index.php/api/User/editPersonalInfo",
    params
    ).then(res=>{}).catch((err)=>{})

  • 相关阅读:
    在C#中使用消息队列RabbitMQ
    从url到页面经历了什么
    jsonp跨域远离
    DNS预处理
    一个架构师需要考虑的问题
    angular2和Vue2对比
    图片多的问题
    xinwenti
    xss和csrf
    ajax是什么
  • 原文地址:https://www.cnblogs.com/lwj820876312/p/9494750.html
Copyright © 2011-2022 走看看