【问题标题】:How can I set dynamic value inside the vue href link?如何在 vue href 链接中设置动态值?
【发布时间】:2021-01-09 20:24:04
【问题描述】:

我正在尝试在 href 中的 URL 中设置动态值。我正在使用 Vue.js

 <a
          href="https://example.com/glasses/guide-for-uploading"
          target="_blank"
        >
          Check it here
        </a>

所以在 URL 的中间,我需要用 productName 替换 glass。如何在此链接中正确完成?我不确定是否是简单的数据绑定。

【问题讨论】:

    标签: vue.js vuejs2 vue-component


    【解决方案1】:

    是的,您可以使用数据绑定。

    <a
              :href="`https://example.com/glasses/${productName}`"
              target="_blank"
            >
              Check it here
            </a>
    

    【讨论】:

      【解决方案2】:

      你可以像这样绑定href:

      :href="'https://example.com/glasses/${productName}'"
      

      或者你可以使用字符串达到同样的效果:

      Let link = document.getElemntById("linkId")
      Let address = "https://example.com/glasses/" + this.productName
      
      link.href = address
      
      

      【讨论】:

        【解决方案3】:

        你可以使用 :href="!${url}!" 它对我有用,将 ! 替换为后引号(`)cold not display 因为它使用突出显示此编辑器中的内部部分

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-03-01
          • 1970-01-01
          • 1970-01-01
          • 2022-07-05
          • 1970-01-01
          • 1970-01-01
          • 2021-01-01
          相关资源
          最近更新 更多