在vuejs中将旧代码修改为vue router 4

Lui*_*ves 9 vue.js vue-router

在 Vue Router 4 之前,我有以下标记:

<router-link
              :disabled="!ICanGo(item)"
              :tag="!ICanGo(item) ? 'span' : 'a'"
              :event="ICanGo(item) ? 'click' : ''"
              :to="{ name: 'editUsuario', params: { id: item.id } }"
>{{ item.nome }}</router-link>
Run Code Online (Sandbox Code Playgroud)

使用 Vue Router 4,我现在有以下警告:

[vue-router]
<router-link>'s tag prop is deprecated and has been removed in Vue Router 4. Use the v-slot API to remove this warning: https://next.router.vuejs.org/guide/migration/#removal-of-event-and-tag-props-in-router-link. 
Run Code Online (Sandbox Code Playgroud)

我怎样才能将此代码更改为 Vue Router 4 建议?

ton*_*y19 9

根据's文档<router-link>v-slot,Vue Router 4 中的等价物是:

<router-link
  :to="{ name: 'editUsuario', params: { id: item.id } }"
  custom
  v-slot="{ href, navigate }"
>
  <span v-if="!ICanGo(item)">{{ item.nome }}</span>
  <a v-else :href="href" @click="navigate">{{ item.nome }}</a>
</router-link>
Run Code Online (Sandbox Code Playgroud)

!ICanGo(item)因为<span>在这种情况下本身没有链接激活,所以不需要禁用该元素。

演示