如何使用JSDOC使用脚本设置来记录VUE组件?
我正在建立一个带有打字稿的VUE库。我想像普通功能一样导出组件的文档。
以前我们会这样做:
<script>
/**
* This is the documentation of my component.
*/
export default {
}
</script>
<template></template>
但是现在使用脚本设置
:
<script setup lang="ts">
</script>
<template></template>
我们如何记录组件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
&lt;脚本设置&gt;
您不能在组件导出上使用jsdoc。这是一种编译器的语法糖,可以消除设置功能的导出,因此您显然无法评论编译器“生成”的函数。
如果您确实需要JSDOC,则应使用默认导出的常规
&lt; script&gt;
::)还可以使用Typescript decarecomponent wrapper 包装器:
edit:edit:如@estusflask提到:在评论中,您可以在sfc组件上同时混合
&lt; scipt设置&gt;
和&lt; script&gt;
(请参阅 docs )因此,您可以使用常规脚本揭露JSDOC。
With
<script setup>
you can't use JSDoc on the component export.It's a compiler syntaxic sugar that gets out the export of the setup function, so you obviously can't comment a function that is "generated" by the compiler.
If you really needs JSDoc, you should use a regular
<script>
with a default export :)Also works with the typescript
defineComponent
wrapper:EDIT: as mentionned by @EstusFlask in the comments, you can mix both
<script setup>
and<script>
on a SFC component (see docs)So you can use the regular script to expose your JSDoc.
我没有声誉可以评论 https://stackoverflow.com/a/a/72003725/18059097 ,但是看来您甚至不需要将任何内容都放在默认导出中,因此您可以简单地
使用此样式也可以是有利的,以便您可以使用编辑器的“转到参考”功能,尽管它有点一个愚蠢的解决方法。
另一个稍有不同的想法是创建一个单独的文件
index.js
,并且当然是文档中的缺点。
I don't have the reputation to comment on https://stackoverflow.com/a/72003725/18059097 or I would, but it seems you don't even need to put anything in the default export, so you can simply do
Using this style can also be advantageous so that you have a way to use the editor's Go To References feature, though it's a bit of a silly workaround.
Another slightly different idea is to create a separate file
index.js
and doThis of course has the downside of the documentation being in a separate file though.