租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

vue怎么获取header里面的值,vue怎么获取后端数据

发布时间:2023-08-07 07:56:47

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要求并获得要求头中的值。