Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Menu] 当项目不包含 vue-router 时,会产生额外的 warning #4718

Open
dsh0416 opened this issue Nov 10, 2024 · 1 comment
Open
Labels
🐞 bug Something isn't working

Comments

@dsh0416
Copy link

dsh0416 commented Nov 10, 2024

tdesign-vue-next 版本

1.10.3

重现链接

No response

重现步骤

  1. 初始化一个不含 vue-router 的项目
  2. 插入一个 Menu 元素(如下代码)
<template lang="pug">
t-layout
  t-header
    t-head-menu(v-model="activeRoute")
      t-menu-item(value="foo")
        | Foo
  t-layout
    t-aside Aside
    t-content
      slot
  t-footer Footer
</template>

<script lang="ts" setup>
import { ref } from "vue";

const activeRoute = ref("foo");
</script>

期望结果

正常使用

实际结果

报了如下 warning

[Vue warn]: Property "$router" was accessed during render but is not defined on instance. 

框架版本

No response

浏览器版本

No response

系统版本

No response

Node版本

No response

补充说明

我们业务场景围绕 ruby on rails 和 inertia.js,所以不需要 vue-router 组件。现在情况会报 vue warn,虽然不影响使用,但满屏幕的 warning 挺影响调试的。

问题来自

const router = this.router || this.$router;
即使我不使用 RouterLink,此处也会 eagerly 初始化 router 变量。可以通过某种方法改成惰性的。

一个 workaround 是手动传入 menu-item(:router="{}")

Copy link
Contributor

👋 @dsh0416,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@dsh0416 dsh0416 changed the title [Menu] 描述问题的标题 [Menu] 当项目不包含 vue-router 时,会产生额外的 warning Nov 10, 2024
dsh0416 added a commit to dsh0416/tdesign-vue-next that referenced this issue Nov 10, 2024
@uyarn uyarn added the 🐞 bug Something isn't working label Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants