如何在Vue.js中访问这个JSON?

huangapple go评论56阅读模式
英文:

how can i access this json in vuejs

问题

这是我的JSON

{
    "Response": {
        "Error": {
            "ErrorCode": 0,
            "ErrorMessage": ""
        },
        "Results": {
            "FareBreakdown": [{
                    "Currency": "INR"
                }
            ],
            "FareRules": [{
                "Origin": "DEL"
            }]
        }
    }
}

这是我的脚本

const response = await axios.post(
    "http://localhost:5000/api/fare-quote",
    requestData
);

this.searchResult = response.data.Response.FareBreakdown;

console.log(this.searchResult)

我在控制台中得到了"undefined"

这是我在模板中使用来显示数据的方式

{{searchResult}}

我得到了一个良好的响应,但我只是尝试在我的模板中显示数据。

英文:

this is my json

{
    "Response": {
        "Error": {
            "ErrorCode": 0,
            "ErrorMessage": ""
        },
        "Results": {
            "FareBreakdown": [{
                    "Currency": "INR"
                }
            ],
            "FareRules": [{
                "Origin": "DEL"
            }]
        }
    }
}

this my script

   const response = await axios.post(
          "http://localhost:5000/api/fare-quote",
          requestData
        );

        this.searchResul = response.data.Response.FareBreakdown;

        console.log(this.searchResul)

i get undefined in my console

this how i use in my template to show the data

 {{searchResul}}

i get a good response but i'm just trying to display the data in my template

答案1

得分: 2

以下是已翻译的内容:

this.searchResul = response.data.Response.Results.FareBreakdown;

然后在你的模板中:

<li v-for="item in searchResul" :key="item.Currency">
  货币: {{ item.Currency }}
</li>
英文:

do these

  this.searchResul = response.data.Response.Results.FareBreakdown;

then in your template

 &lt;li v-for=&quot;item in searchResul&quot; :key=&quot;item.Currency&quot;&gt;
      Currency: {{ item.Currency }}
      &lt;/li&gt;

huangapple
  • 本文由 发表于 2023年7月10日 20:40:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76653839.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定