【问题标题】:following links in vue with button在带有按钮的vue中跟随链接
【发布时间】:2019-04-12 10:48:20
【问题描述】:

祝大家好运。我在使用以下链接时遇到了问题。

我需要为按钮分配链接。我可以将 router-link 包装在一个按钮中吗?

<template lang="html">
    <button @click="" v-if="status == 'SUCCESS'"><font-awesome-icon icon="check" /></button>
    <button @click="" v-else-if="status == 'CRASH'"><font-awesome-icon icon="times" /></button>
    <button @click="" v-else-if="status == 'NO_DATA'"><font-awesome-icon icon="minus" /></button>
    <button v-else>What?</button>
</template>

【问题讨论】:

  • 虽然这是可能的,但您能否解释一下为什么不能将按钮设为锚点?这种解决方案会简单得多。
  • @Daniel 主播?在 vue 中怎么可能?
  • @Stepykun 你在用 vue-router 吗?
  • 你能证明vue-router的用法吗?很难说你想要完成什么。

标签: javascript vue.js vue-router


【解决方案1】:

只需将:to="" 值分配给您的按钮,它就会变成有效的vue-router 链接。

例如:

<button :to="{name: 'Home'}" />

会变成:

<a href="/index"></a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 2015-07-05
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多