Uncaught TypeError: Cannot read properties of undefined (reading 'format')
时间: 2023-10-17 10:15:24 浏览: 54
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决
5星 · 资源好评率100%
This error occurs when you try to access a property or method of an undefined or null value.
In this specific case, it seems like you are trying to access the 'format' method of an undefined variable. You need to make sure that the variable is defined and not null before trying to access its properties or methods.
For example, if you are trying to format a date using moment.js:
```
let myDate = undefined;
// some code that sets the value of myDate
if (myDate) {
let formattedDate = myDate.format('MM/DD/YYYY');
}
```
In this example, we check if myDate is defined before trying to format it. If it is undefined, the if statement will not execute and we avoid the "Cannot read properties of undefined" error.
阅读全文