What is the style and structure of the data that vue receives from the background?

Is

like this?

var msg=[
        {content: {a: 111, b: "ccc"}, uid: {a: 111, b: 222, c: 333, flag: {f1: false, f2: true, f3: false}}},
        {content: {a: 222, b: "ccc"}, uid: {a: 444, b: 555, c: 666, flag: {f1: true, f2: true, f3: false}}}
      ];

or is it something like this? In the first way, it is very difficult to transfer the uid data to the subcomponents to process the data. the following writing method is much easier for the subcomponents to deal with. This is just the data I simulated. I don"t know what it will be like to receive it from the background in the future. Which of these two formats is more formal?

var msg: [
        {content: {a: 111, b: "ccc"}, uid: {num: [111, 222, 333], flag: [false, true, true]}},
        {content: {a: 222, b: "ccc"}, uid: {num: [444, 555, 666], flag: [false, true, true]}}
      ]
Apr.27,2021

whatever format you want, just let the background make it.


how to design this interface data structure

still depends on how the page function is planned, so that the data structure can be "friendly" to the page function

so how to judge "friendly"

you can only try it yourself


the data format returned by the backend API may not be used directly. Generally, it can be used after conversion, and it can be transferred on its own when the workload is not heavy. If I really can't, I'll call the back-end to change the format.


1. If you can tear the back end and change it to the second one, then the second one.
2, tear can not win, well, then get the first, write their own conversion method, convert to the data format you want, it is nothing more than a few loops to solve the problem.


generally backend returns the second type, but if you look at people, you can ask the backend to return the format you need


this depends on the data type given by the background. You can print it out, and axios interceptor to learn about


.

generally speaking, it is a JSON object

var res = {
    Code: 200,
    Data: [
        {
            name: 'zs',
            age: 18
        },
        {
            name: 'ls',
            age: 16
        }
    ],
    Message: ''
}

code indicates status code, 200 indicates success, others are defined by yourself, data represents the returned data set, and message represents additional text information.

Menu