Solution to calling data in data in vue callback function

Scene: `

Call the data in data in the vue callback function
screenshot

Problem Description

Click a button on the page and a pop-up window will pop up. After the user clicks OK, the data will be recorded in the log. Judging from the running log, the value of the message defined in data cannot be obtained in the callback function.

Cause Analysis:

The this of the callback function only represents the variables within the scope of the callback function.


solution:

Define a variable outside the callback function and assign it the this object outside the callback function. In this way, the variables defined in data can be called normally within the callback function.

var homeThis = this;

Successful screenshot

Guess you like

Origin blog.csdn.net/liangxiaoyan0426/article/details/131348436