【问题标题】:Vue 3: component not rendering when added with router-viewVue 3:使用路由器视图添加时组件不呈现
【发布时间】:2021-10-25 05:09:54
【问题描述】:

我使用 vue-cli 创建了 vue 应用程序,而不是 html,我为链接添加了我的组件 TopBar,并且这些链接没有被渲染。

App.vue

<template>
  <TopBar />
  <router-view />
</template>
<script>
import TopBar from "./components/TopBar.vue";

export default {
  components: [TopBar],
  setup() {},
};
</script>

TopBar.vue

<template>
  <div id="nav">
    <router-link to="/">Home</router-link> |
    <router-link to="/about">About</router-link>
  </div>
</template>

vue create命令提供的这个代码模板,我只是把链接移到TopBar.vue

我错过了什么吗?

【问题讨论】:

    标签: vue-router vuejs3


    【解决方案1】:

    找到解决办法,

    组件应该对象 {} 而不是数组 []。

    <template>
      <TopBar />
      <router-view />
    </template>
    <script>
    import TopBar from "./components/TopBar.vue";
    
    export default {
      components: {TopBar}, // <== here
      setup() {},
    };
    </script>
    

    【讨论】:

      猜你喜欢
      • 2017-07-31
      • 2021-06-22
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 2022-08-22
      • 2019-06-26
      • 2019-03-04
      • 2021-05-06
      相关资源
      最近更新 更多