我正在try 在我的单文件Vue组件上运行JSDoc.我发现了两个听起来应该可以工作的插件(两个插件实际上似乎基于相同的代码):

https://www.npmjs.com/package/vue-doc

https://www.npmjs.com/package/jsdoc-vue

The plugin breaks when shorth和 is used, but that's not a big issue, I can just use longh和. However every single file component I try to run JSDoc on gets this error:

相邻的JSX元素必须包装在一个封闭的标记中

这意味着我的组件没有一个根元素,但它们都有.我像这样设置了一个测试组件,但失败了:

<template>
  <div>
    {{someData}}
  </div>
</template>

<script>
  export default {
    data () {
      return {
        someData: "Test Data"
      }
    },
    methods: {
      /**
       * Just a test function
       * @function
       */
      testFunction: function () {
        alert("Testing")
      }
    }
  }
</script>

<style lang="stylus">
  div {
    border: 1px solid;
  }
</style>

有没有人有在上运行JSDoc的经验.vue文件?这似乎是可能的,但网上的信息很少.

谢谢

推荐答案

我一直在用documentation.js来记录我的Vue文件.Here's an excellent article关于如何开始使用它.它的易用性给我留下了深刻的印象,它生成了好看的HTML文件,可以用来轻松搜索您编写的函数.

例如,如果您创建如下Vue文件:

<template>
    <div>{{mydata}}</div>
</template>

<script>
export default {
    data: function() {
        return {
            mydata: "hello"
        }
    },
    methods: {
        /**
         * Add two numbers.
         * @param{number} num1 The first number to add
         * @param{number} num2 The second number to add
         * @return{number} The sum of the two numbers.
         */
        addnums: function(num1, num2) {
            return num1 + num2;
        },

        /**
         * Concatenate two strings.
         * @param{string} str1 The first string to concatenate.
         * @param{string} str2 The second string to concatenate.
         * @return{string} The concatentation of the two strings.
         */
        concat: function(str1, str2) {
            return str1 + str2;
        }
    }
}
</script>

运行documentation build /path/to/file.vue -f html -o docs将创建一个漂亮的HTML文件,在浏览器中如下所示:

enter image description here

2019 EDIT:

我昨天发现了一个名为vuese的新库,它是专门为记录Vue组件而构建的.而文件.js将在帮助您记录方法方面做得很好,vuese通过允许您将文档添加到props 和组件中,更进一步.它非常容易使用.

我几乎从this blog post中学到了我需要知道的一切.

Vue.js相关问答推荐

Nuxt 3 I18N浏览器检测不起作用

有没有办法在 Quasar 中为明暗模式创建我自己的 colored颜色 ?

两个div元素之间的vue2过渡

VueJS中的绑定函数含义

apache上的Vue-router,子目录下的SPA,只能通过重定向访问页面

Vuex - 如何跨不同选项卡持久存储更新?

v-for 中的 VueJS 插槽

如何从 bootstrap-vue 模态监听事件?

SassError:媒体查询表达式必须以(开头

Vue 如何使用 slot 和 slot-props 测试组件

Jest错误找不到模块....

在手动安装的 vue 组件中使用 vuex

错误:Node Sass 尚不支持您当前的环境:Linux 64-bit with Unsupported runtime (88)

如何将数据属性设置为从 Vuex getter 返回的值

样式化 Vue 插槽

vue组件中导入和使用three.js库

使用 Vue.js & DataTable(jquery 插件)

嵌套组件

如何从组件内的单点捕获 vuejs 错误

如何从 Vuex 操作访问 Vuex 状态属性?