uview2.0 uses the formatter attribute of u-calendar, the bug that this cannot be accessed in the formatter method, the solution! ! ! !

uview version 2.0.36

document

Using the example of this document, printing this in the formatter will also be undefined.

I wrote a demo myself. The parent passes a function to the child through v-bind, and then prints this in this function. This is an instance of the child component, but I don’t know why undefined is printed in the formatter. I hope that the big brother who will meet will give me some pointers in the comment area.

The solution is to define a variable externally, and then assign this variable this in the onload of the parent that calls the calendar component, and then the formatter can print out the parent's this, and then access the parent variable.

 

 

 The second method is to modify the source code of u-calendar. In order not to affect other modules that use the calendar component, finally extract the code in the component and encapsulate a component by yourself. Then get the back-end data inside the calendar component, and then pass it to the formatter function.

 The first formal parameter is config, you can put the data you want to operate in the second formal parameter, and then you can use it in the formatter.

Guess you like

Origin blog.csdn.net/m0_57033755/article/details/131816328