• vue项目中请求头为applicationx-www-form-urlencoded的参数传递


    当请求接口的请求头如下图所示时,

    前端在传参时需要先新建一个URLSearchParams对象,然后将参数append到这个对象中

    const params = new URLSearchParams();
    params.append('programId', row.programId)

    然后再将该对象传递到接口参数

     program_submit(params).then(res => {
            if (res.data.code == '0') {
              that.$openMessage('提交成功', 'success');
              this.getAllprogram();
            } else {
              that.$openMessage(res.data.msg, 'error');
            }
          }).catch(e => {
            that.$openMessage(e, 'error');
          })
        },

    对应的axios的接口如下,需要加个headers

    export function program_submit(params) {
    return axios.put(servers + '/program/submit', params, {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    });
    }

     补充:

    一般getdelete请求,param要加大括号{ },而put和post则不用加

  • 相关阅读:
    使用 PyCharm 远程调试 Django 项目
    (坑集)Python环境配置
    字典的使用
    列表的使用
    字符串的魔法
    php 文件函数
    php 时间函数
    php xajax库基本知识
    php header函数
    c++注释
  • 原文地址:https://www.cnblogs.com/thinkguo/p/11277313.html
Copyright © 2020-2023  润新知