简体   繁体   English

如何在vuejs中获取http请求响应的值

[英]how to get the value of a http request response in vuejs

Actually what I wants to know is how to get the value of the name in Vuejsof a http request.Please see the image for the Chrome console click here to see the console to get the value of name i have written below code at Register.vue .But after user registration it shows under application tab of chrome name is undefined. 实际上我想知道的是如何在http请求的Vuejs中获取名称的值。请查看Chrome控制台的图像, 单击此处以查看该控制台获取我在Register.vue的代码下方编写的名称的值。但是,在用户注册后,它在chrome名称的应用程序选项卡下显示为未定义。

 .then((response) => {
      console.log(response)
      let accessToken = response.data.access_token
      localStorage.setItem('token', accessToken)
      localStorage.setItem('user', response.config.data.name)

So could anyone please tell me how to get the value of name. 所以任何人都可以告诉我如何获得名称的价值。

response.config.data is a String (see the double qoutes). response.config.data是一个字符串(请参见双qoutes)。 You need to parse it (JSON.parse) and then you can take the name property. 您需要对其进行解析(JSON.parse),然后可以使用name属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM