首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用传单-vue-3我如何打开一个特定的现有弹出按钮?

使用传单-vue-3我如何打开一个特定的现有弹出按钮?
EN

Stack Overflow用户
提问于 2022-07-19 04:38:35
回答 1查看 216关注 0票数 1

我在传单上有一堆标记

代码语言:javascript
复制
   <l-marker
        v-for="station in stations"
        :lat-lng="[station.lat, station.lon]"
        :options="{title: station.stationname}"
        autoPanOnFocus="true"
        keyboard="true"
        @click="closeAll()"
    >

 <l-icon :icon-size="[15,15]" :icon-url="'/img/bus.png'"/>
 <l-popup>
 .....
 </l-popup>
</l-marker>

如何编写一个方法,当单击按钮时,该方法将以编程方式识别和打开特定的弹出窗口?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-20 05:16:36

这个问题的答案是使用ref,并调用ref的value.leafletObject.openPopup()函数。

若要在Vue3组合API中创建参考文献,请使用v-for模板引用将参考文献分配给标记。

代码语言:javascript
复制
        <l-marker
        v-for="station in stations"
        ref="stationRefs"
        :lat-lng="[station.lat, station.lon]"
        :options="{title: station.stationname}"
        autoPanOnFocus="true"
        keyboard="true"
        @click="closeAll()"
    >

在脚本中定义v-for引用。

代码语言:javascript
复制
import { ref } from "vue";

const stationRefs = ref([])

并从方法调用openPopup:

代码语言:javascript
复制
function nextStop(stops, station, stations, currentStop, itinerary) {
    let nextStop = stops.find((stop) => stop.itinerary_id == itinerary.id && stop.order == currentStop.order + 1);
    let nextStation = stations.find((station) => station.id == nextStop.station_id);
    if (nextStop) {

        let nextStopMarker = stationRefs.value.find((marker) => marker.options.title == nextStation.stationname);

        nextStopMarker.leafletObject.openPopup();

    } else {
        swal.fire({
            title: "No Next Stop",
            text: "There are no more stops for this itinerary",
            icon: "warning",
            button: "OK"
        });
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73031187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档