How does vue handle json unpassed fields?

problem description

json contains a large number of fields, and the backend cannot determine whether a certain field will be included in the json. It is not realistic to declare one by one at the front end, and the page that references no fields will report an error. How to solve such a situation?

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Jun.29,2021

all fields are fault-tolerant when taking values

var a = obj.b || ''

ts or flow is recommended.

if it is inconvenient, the project can use its own detection method.

such as a.b | |'.

if your project is complicated, you can use jsonschema

  var Validator = require('jsonschema').Validator;
  var v = new Validator();
 
  // Address, to be embedded on Person
  var addressSchema = {
    "id": "/SimpleAddress",
    "type": "object",
    "properties": {
      "lines": {
        "type": "array",
        "items": {"type": "string"}
      },
      "zip": {"type": "string"},
      "city": {"type": "string"},
      "country": {"type": "string"}
    },
    "required": ["country"]
  };

if you find the two more troublesome, you can use some plug-ins to do these operations for you.

for example, your code is written like this:

obj.a.b.c

help you escape like this:

obj&& obj.a && obj.a.b && obj.a.b.c

remove the backend, but sometimes the front end still has a

that handles the default values for those fields.
Menu