vue报错: “TypeError: Cannot read properties of undefined (reading ‘0‘)“

A pit in Vue: vue.esm.js?c9fd:628 [Vue warn]: Error in render: “TypeError: Cannot read properties of undefined (reading '0')”; 1. Cause: Data used on the
page When it is nested with multiple layers, for example, the data of the third layer of the array is displayed, such as data[0][0]. When the page is initialized, an error will be reported: Cannot read properties of undefined (reading ' 0'); but the page can be used normally.

2. Reason:

 **The data to be displayed is obtained through an asynchronous method. At the beginning, the initial data is empty, and the error is reported because an error is reported when displaying the initial data** 1 3. Solution: Avoid
displaying
analysis when there is no data (with data Only parse), div only exists when there is data, use v-if to control it

4. Supplement: If the custom calendar component is used in the project, when the calendar data is initialized, if the data structure of the data to be displayed is more complicated, such as data[0][1], it is best to write the method to created( ) method, instead of mounted(), to avoid the above error,

Guess you like

Origin blog.csdn.net/kuang_nu/article/details/129585927