【发布时间】:2021-10-11 03:56:45
【问题描述】:
我一直在使用 jquery 执行一些 dom 操作任务,我需要从 click 事件块中更新我的反应变量。
我有这个反应变量
data() {
return {
inside_image:''
};
},
mounted() {
$("img").click(function() {
var image_string = $(this).attr('src');
this.inside_image = 'https://google.com/'+image_string;
});
我需要更新但我无法访问我的数据响应变量,很可能this 没有指向 vue 数据。有没有一种方法可以让我从点击事件块内部访问我的反应变量?这个块
$("img").click(function() {
var image_string = $(this).attr('src');
//This is currently not updating my reactive vars
this.inside_image = 'https://google.com/'+image_string;
});
【问题讨论】: