vue

vue如何获取header里面的值

小亿
1432
2023-08-05 00:33:47
栏目: 编程语言

在Vue中,你可以通过使用this.$http.headersthis.$http.defaults.headers来获取请求头中的值。这里假设你使用了Vue的官方插件vue-resource

首先,在你的Vue组件中,通过this.$http.headers来获取headers的值。

export default {
created() {
console.log(this.$http.headers.get('Content-Type'));
console.log(this.$http.headers.get('Authorization'));
}
}

或者,你也可以通过this.$http.defaults.headers来获取headers的值,这样可以查看全局的默认请求头。

export default {
created() {
console.log(this.$http.defaults.headers.get('Content-Type'));
console.log(this.$http.defaults.headers.get('Authorization'));
}
}

请注意,你需要在Vue组件中正确设置vue-resource插件并进行相应的配置,以便正确地发送HTTP请求并获取请求头中的值。

0
看了该问题的人还看了