Home > front end >  Vue attributes of the object rendered null error, have what good solution?
Vue attributes of the object rendered null error, have what good solution?

Time:09-18

render null object properties, vue complains, lead to render error page
Now I know two ways, can come to check the empty, but the two ways, feel the limitation is very high, you have any other solution?
Here is my solution
Solution 1, judge when the object is null in the output

{{item. Named orderdetail. Info==null? 'null' : item named orderdetail. Info. FullName}}

Solution 2: v - if the judgement, if null don't render the dom

looking forward to your solution: unified inspection on null objects, and initialize some numerical,

CodePudding user response:

Now think of a way:

In will return to the information database, assigned to the js object, if the object is null, then the reset to statement object
Vm: is it a new Vue ()

 axios. Get ('/getUserOrders' {
Params: {
PageSize: enclosing pageSize,
CurrentPage: enclosing currentPage,
}
{}). Then (function (responseDate)
//responseDate is to receive the returned information, judge the inside of the object, if is null, then this object to the object of the declaration
For (let dataValue of responseDate. Data. The data) {
If (dataValue. FounderClass===null) {
DataValue. FounderClass=vm. OrderDate. Data. FounderClass;
}
Let named orderdetail=dataValue. Named orderdetail;
If (named orderdetail===null) {
Named orderdetail=vm. OrderDate. Named orderdetail;
} else {
If (named orderdetail. ResponsiblePersonClass==null) {
Named orderdetail. ResponsiblePersonClass=vm. OrderDate. Data. ResponsiblePersonClass;
}
If (named orderdetail. PrepaymentCashierClass==null) {
Named orderdetail. PrepaymentCashierClass=vm. OrderDate. Data. PrepaymentCashierClass;
}
If (named orderdetail. FinalPaymentCashierClass==null) {
Named orderdetail. FinalPaymentCashierClass=vm. OrderDate. Named orderdetail. FinalPaymentCashierClass;
}
}
}
Vm. OrderDate=responseDate. Data;
The console. The log (vm. OrderDate);
{}). The catch (function (error)

})
}
  • Related