如何使用Typescript,Pug Template Engine和Coption API在VUE3中创建组件

发布于 2025-01-30 11:04:51 字数 358 浏览 0 评论 0 原文

当我在<脚本设置中导出组件时但从未使用过。 例如:

<template lang="pug">
div
  // In kebab-case e.g. hello-world also have same issue
  HelloWorld
</template>
<script setup lang="ts">
import HelloWorld from'@/components/HelloWorld.vue';
</script>

这是投掷 错误: 'Helloworld'已定义但从未使用过

When I am exporting components inside <script setup lang="ts"> and using in <template lang="pug">, it's throwing error, defined but never used.
For example:

<template lang="pug">
div
  // In kebab-case e.g. hello-world also have same issue
  HelloWorld
</template>
<script setup lang="ts">
import HelloWorld from'@/components/HelloWorld.vue';
</script>

This is throwing
Error: 'HelloWorld' is defined but never used

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后知后觉 2025-02-06 11:04:52

我发现了这个解决方案:

<template lang="pug">
div
  // In kebab-case e.g. hello-world also have same issue
  HelloWorld
</template>

<script setup lang="ts">
import HelloWorld from'@/components/HelloWorld.vue';
</script>

<script lang="ts">
export default {
  components: {
    HelloWorld,
  }
}
</script>

因此,主要思想是我们应该清楚地定义我们的组件。根据如果需要的话,我们可以使用2个脚本标签!

希望它有用

I found this solution:

<template lang="pug">
div
  // In kebab-case e.g. hello-world also have same issue
  HelloWorld
</template>

<script setup lang="ts">
import HelloWorld from'@/components/HelloWorld.vue';
</script>

<script lang="ts">
export default {
  components: {
    HelloWorld,
  }
}
</script>

So, the main idea is that we should clearly define our components. According to https://vuejs.org/api/sfc-script-setup.html#usage-alongside-normal-script we can use 2 script tags, if we need!

Hope it was useful

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文