繁体   English   中英

VueJS @click 传递数据

[英]VueJS @click pass data

我正在使用 vue-google-maps 并尝试在我的地图上绘制多边形。 在这一点上,我很好,但我想在我的点击地图上获得纬度和经度位置。 当我这样做时

<GmapPolygon v-for="cabstand in cabstands" :path="cabstand.positions" @click="getCabstandClick"/>

在我的方法中

getCabstandClick(data) {
    console.log(data);
}

我可以得到一个具有 lat & lng 位置的对象,但我必须触发 2 种方法,所以我使用了这样的方法

<GmapPolygon v-for="cabstand in cabstands" :path="cabstand.positions" @click="getCabstandClick ; getCabstandInfos(cabstand)"/>

而且我的控制台中没有日志,好像它不再执行我的第一个方法。 我试过; 在我的两种方法之间,使用&&但这总是一样的。

任何人都可以帮助我吗?

谢谢,

单击时调用一个调用这两种方法的方法:

<GmapPolygon v-for="cabstand in cabstands" :path="cabstand.positions" @click="callBothMethods(cabstand)"/>

methods: {
    callBothMethods(cabstand) {
        this.getCabstandClick();
        this.getCabstandInfos(cabstand);
    }
}

好的,我终于找到了解决方案:我在我的方法中使用了$event变量。

<GmapPolygon v-for="cabstand in cabstands" :path="cabstand.positions" @click="getCabstandInfos(cabstand, $event)"/>

谢谢你的帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM