vue ajax axios 注意:使用axios时 后端接受需要 在 $param['params'] 参数后面加 params

new Vue({
   
    el: "#app",
    methods: {
   
        fileUpload: function () {
   
            console.info("sbkjauth:" + localStorage.getItem("sbkjauth"));
            var _this = this;
            var formData = new FormData();
            formData.append("uploadFile", $("input[name='uploadFile']")[0].files[0]);
            axios({
   
                method: "post",
                url: "/auth/fileUploadLocal" + getSign(),  // 算签名,不需要可以去掉
                data: formData,
                headers: {
   
                    'Content-Type': 'multipart/form-data',  // 文件上传
                    // 'Content-Type': 'application/x-www-form-urlencoded',  // 表单
                    // 'Content-Type': 'application/json;charset=UTF-8'  // json
                    "sbkjauth": localStorage.getItem("sbkjauth")  // token ,不需要可以去掉
                },
            }).then(function (response) {
   
                console.log(response);
                alert(response.data.message);
            }).catch(function (reason) {
   

            })
        },

    }
});

区别 后端接受需要 在 $param['params']   
               axios.post('del', {
   
                    params: {
   
                        id: id
                    }
                }).then(function (res) {
   
                    if (res.data.code) {
   
                        layer.alert(res.data.msg);
                    } else {
   
                        layer.alert(res.data.msg);
                    }
                }).catch(function (error) {
   
                    console.log(typeof +error)
                })
                <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

/* axios v0.19.0 | (c) 2019 by Matt Zabriskie */
!function(e,t){
   "object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.axios=t():e.axios=t()}(this,function(){
   return function(e){
   function t(r){
   if(n[r])return n[r].exports;var o=n[r]={
   exports:{
   },id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={
   };return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){
   e.exports=n(1)},function(e,t,n){
   "use strict";function r(e){
   var t=new i(e),n=s(i.prototype.request,t);return o.extend(n,i.prototype,t),o.extend(n,t),n}var o=n(2),s=n(3),i=n(5),a=n(22),u=n(11),c=r(u);c.Axios=i,c.create=function(e){
   return r(a(c.defaults,e))},c.Cancel=n(23),c.CancelToken=n(24),c.isCancel=n(10),c.all=function(e){
   return Promise.all(e)},c.spread=n(25),e.exports=c,e.exports.default=c},function(e,t,n){
   "use strict";function r(e){
   return"[object Array]"===j.call(e)}function o(e){
   return"[object ArrayBuffer]"===j.call(e)}function s(e){
   return"undefined"!=typeof FormData&&e instanceof FormData}function i(e){
   var t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer}function a(e){
   return"string"==typeof e}function u(e){
   return"number"==typeof e}function c(e){
   return"undefined"==typeof e}function f(e){
   return null!==e&&"object"==typeof e}function p(e){
   return"[object Date]"===j.call(e)}function d(e){
   return"[object File]"===j.call(e)}function l(e){
   return"[object Blob]"===j.call(e)}function h(e){
   return"[object Function]"===j.call(e)}function m(e){
   return f(e)&&h(e.pipe)}function y(e){
   return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams}function 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值