简体   繁体   English

显示来自rest api的json响应的Vue问题

[英]Vue problem with display of json response from rest api

I have a problem with displaying my response which i get from rest API.我在显示从 rest API 获得的响应时遇到问题。 After I get response I'm using JSON.stringify to make it like below, then I'm calling action which call a mutation which save it in my store in cars: [] .得到响应后,我使用 JSON.stringify 使其如下所示,然后我调用 action 调用一个将它保存在我的cars: []商店中的突变cars: [] The variable cars[] in my store and response looks like below so everything is going fine with this.我商店中的变量cars[]和响应如下所示,因此一切正常。

[
  {
    "id":1,
    "vin":11111,
    "register_number":"asdasd",
    "cost":1.32,
    "latitude":50.875883,
    "longitude":20.634377,
    "service":false,
    "reservation":false
  },
  {
    "id":2,
    "vin":2222,
    "register_number":"asdasd",
    "cost":1.3,
    "latitude":50.4244,
    "longitude":20.3323,
    "service":true,
    "reservation":false
  }
]

Then i'm trying to display it.然后我试图显示它。 I use vue getter to get this response from store, if I use getter like <li> {{gettername}} </li> then I can see my data like above but when i want to display them using <v-for="car in CARS" v-bind:key="car"> {{car}} </v-for> then due this key i think i'm getting strange things like this:我使用 vue getter 从商店获取此响应,如果我使用像<li> {{gettername}} </li>这样的 getter,那么我可以像上面一样看到我的数据,但是当我想使用<v-for="car in CARS" v-bind:key="car"> {{car}} </v-for>显示它们时<v-for="car in CARS" v-bind:key="car"> {{car}} </v-for>然后由于这个钥匙,我想我会遇到这样的奇怪事情:

[
{
"
i
d
"
:
1
,
"
v
i
n
"
: (when every single sign is in another row ..) 

Like every singe letter is taken as a object or something.... i just wanna display in rows parameters of my car like:就像每个单字母都被当作一个对象或其他东西一样......我只想在我的汽车的行中显示参数,例如:

"id":1,"vin":11111,"register_number":"asdasd","cost":1.32,"latitude":50.875883,"longitude":20.634377,"service":false,"reservation":false "id":2,"vin":2222,"register_number":"asdasd","cost":1.3,"latitude":50.4244,"longitude":20.3323,"service":true,"reservation":false "id":1,"vin":11111,"register_number":"asdasd","cost":1.32,"latitude":50.875883,"longitude":20.634377,"service":false,"reservation":false " id":2,"vin":2222,"register_number":"asdasd","cost":1.3,"latitude":50.4244,"longitude":20.3323,"service":true,"reservation":false

Then i need to bind them for editing and sending update request to my backend.然后我需要绑定它们以进行编辑并将更新请求发送到我的后端。 Help me please to resolve and understand this problem.请帮助我解决和理解这个问题。 Best regards!此致!

This is a snippet to show the difference between a string and an array:这是显示字符串和数组之间区别的片段:

 (async function() { const todo = await fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => { return json }) const stringified = JSON.stringify(todo) console.log('JSON object:') console.log(todo) console.log('Stringified JSON:') console.log(stringified) })();

In the snippet above we receive a todo JSON object, and then console.log() the object itself and a stringified version.在上面的代码片段中,我们收到一个todo JSON 对象,然后console.log()对象本身和一个字符串化的版本。

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

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