Vue Router 在传单弹出窗口中无法正常工作

Vue Router not working properly in Leaflet Popup

我在我的代码库中使用 vue2-leaflet 包装器将 Leaflet 和 Vue 结合在一起。目前,我遇到一个问题,我试图让 Vue $router 在 Leaflet 的弹出窗口中工作。经过我的尝试,这就是我的代码现在的样子。

<template>
  <l-map>
    <l-tile-layer :url="url" />
    <l-marker
      v-for="point in points"
      :key="point.id"
      :lat-lng="point.latLng"
      :icon="point.icon"
    >
      <l-popup :content="displayInfo(point)"/>
    </l-marker>
  </l-map>
</template>
<script>
...
    displayInfo(point) {
      // how it usually works: this.$router.push({ name: 'point', params: { id: point.id } })
     
      // Attempt 1
      // return '<div onclick="routeToPage(' + point.id + ')">' + point.id + '</div><br/>' + point.subject

      // Attempt 2
      // return '<div @click="routeToPage(' + point.id + ')">' + point.id + '</div><br/>' + point.subject

      // Attempt 3
      // return '<router-link to="{ name: \'point\', params: { id: ' + point.id + ' } }">' + point.id + '</router-link><br/>' + point.subject;

      return point.id + '<br/>' + point.subject;
    },

    routeToPage(id) {
      return this.$router.push({ name: 'point', params: { id }
    }

...
</script>

尝试 1 单击弹出窗口中的 id 会出现此错误。

(index):1 Uncaught ReferenceError: routeToReport is not defined
    at HTMLDivElement.onclick

尝试 2 单击 id 不执行任何操作,也没有任何行为。它看起来好像只是普通文本。检查它只显示

<div class="leaflet-popup-content" style="width: 301px;">
    <div @click="routeToPage">39105</div><br>
    Aliquid voluptas animi facilis ipsum ducimus doloremque consequatur nemo porro perferendis atque dolorum quo adipisci perferendis magnam
</div>

尝试 3

<div class="leaflet-popup-content" style="width: 301px;">
    <router-link to="{ name: 'point', params: { id: 39105 } }">39105</router-link><br>
    Aliquid voluptas animi facilis ipsum ducimus doloremque consequatur nemo porro perferendis atque dolorum quo adipisci perferendis magnam
</div>
其中

None 似乎完全从文本中创建了 link,甚至将其注册为路由。对我做错了什么有什么想法吗?

让我知道您是否需要我这边的更多信息,或者如果这对我的问题的描述不明确。

您可能应该这样放置弹出窗口的内容:

<l-popup>
  <div @click= ....> </div>
</l-popup>

这样 div 和 @click 将被 vue 解释为模板。如果你把它放在 :content 中,它只是被认为是文本。