首页 > 解决方案 > 如何在 vue.js 中为 href 使用组件?

问题描述

我想将组件用作 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.jshref

解决方案


您不能将组件用作字符串

试试这个(例子

<script>
import Library from './Library.js'
  export default {
    data() {
      return {
        Library: Library
      }
    }
}
</script>

<template>
  <a :href="Library" target="_blank">test</a>
</template>

推荐阅读