1、ajax 添加请求头

$.ajax({
            url: url,
            type:"post",
            dataType:"json",
            data:data,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("authorization", "authorization");
                XMLHttpRequest.setRequestHeader("timestamp", new Date().getTime());
            },
            success:function (data) {
            },
            error:function (data) {
            }
        })

2、axios 添加请求头

 this.$axios.post(url, data,
        {
          headers: {
            'authorization': 'authorization',
            'timestamp': new Date()
          }
        })
        .then(res => {
        })
service.interceptors.request.use(
  config => {
    config.headers.common['timestamp'] = times;
	config.headers.common['authorization'] = 'authorization'
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐