vue怎样获得header里面的值
在Vue中,你可以通过使用`this.$http.headers`或`this.$http.defaults.headers`来获得要求头中的值。这里假定你使用了Vue的官方插件`vue-resource`。
首先,在你的Vue组件中,通过`this.$http.headers`来获得headers的值。
```javascript
export default {
created() {
console.log(this.$http.headers.get('Content-Type'));
console.log(this.$http.headers.get('Authorization'));
}
}
```
还是,你也能够通过`this.$http.defaults.headers`来获得headers的值,这样可以查看全局的默许要求头。
```javascript
export default {
created() {
console.log(this.$http.defaults.headers.get('Content-Type'));
console.log(this.$http.defaults.headers.get('Authorization'));
}
}
```
请注意,你需要在Vue组件中正确设置`vue-resource`插件并进行相应的配置,以便正确地发送HTTP要求并获得要求头中的值。
TOP