代码之家  ›  专栏  ›  技术社区  ›  Tomer

js路由器链接在firefox上不起作用

  •  0
  • Tomer  · 技术社区  · 7 年前

    我有这个按钮组件:

        <button :class="classes" v-on="$listeners" v-bind="$attrs">
        <template v-if="to">
          <router-link :to="to" class="flex center-v">
            <AqIcon :icon="icon" v-if="icon" />
            <slot></slot>
          </router-link>
    
        </template>
        <template v-else>
          <AqIcon :icon="icon" v-if="icon" />
          <slot></slot>
        </template>
    
      </button>
    

    它可以接受 :to 在这种情况下,我使用路由器链接而不仅仅是文本。

    当我这样使用它时:

    <AqButton primary icon="plus" :to="{name:'editUser',params:{id:'new'}}">
         Add User
    </AqButton>
    

    在chrome上运行良好,但在ff上url会改变,但它会保持在同一个页面上。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Tomer    7 年前

    所以很明显,如果你把路由器链接嵌套在一个按钮元素下,它就不起作用了。

    所以我把组件改成这样:

    <template>
      <router-link v-if="to" :to="to" :class="classes" v-on="$listeners" v-bind="$attrs">
        <AqIcon :icon="icon" v-if="icon" />
        <slot></slot>
      </router-link>
    
      <button v-else :class="classes" v-on="$listeners" v-bind="$attrs">
        <AqIcon :icon="icon" v-if="icon" />
        <slot></slot>
      </button>
    
    </template>
    

    现在它开始工作了。