【问题标题】:How to use components for an href in vue.js?如何在 vue.js 中为 href 使用组件?
【发布时间】:2021-12-17 08:11:51
【问题描述】:

我想将组件用作 a 标签中的 href。 这是我的代码

<template>
    <a v-bind:href="Library">  </a>
</template>

<script>
import Library from './Library';

export default {
    name: "App",
    components: {
        Library,
    },
}
</script>

<style>
    
</style>

很遗憾,我收到一条错误消息,提示我没有使用库组件。 有谁知道怎么做?

亲切的问候 埃米尔

【问题讨论】:

    标签: vue.js href


    【解决方案1】:

    您不能将组件用作字符串

    试试这个 (example)

    <script>
    import Library from './Library.js'
      export default {
        data() {
          return {
            Library: Library
          }
        }
    }
    </script>
    
    <template>
      <a :href="Library" target="_blank">test</a>
    </template>
    

    【讨论】:

    • 我试过了,错误消失了,但是我没有发送到library.vue文件
    • 哦,那是一个非常不同的问题。你需要像vue-router 这样的东西来做到这一点。
    • 哦,好吧,你知道如何在我的代码中快速实现这个,还是我必须自己学习这个
    • 没有快速的方法:/ Vue路由器需要一些阅读和理解。但这将是值得的!以后你肯定会大量使用它! This page 应该让你在几个小时内开始。
    猜你喜欢
    • 2022-11-03
    • 2018-02-14
    • 2017-08-09
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 2018-11-01
    • 2021-03-27
    • 1970-01-01
    相关资源
    最近更新 更多