JSDoc单文件Vue组件

时间:2017-03-16 09:09:05

标签: vue.js jsdoc

我正在尝试在单个文件Vue组件上运行JSDoc。我发现了两个看起来应该工作的插件(两者似乎都基于相同的代码):

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

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

当使用速记时插件会中断,但这不是一个大问题,我可以直接使用。但是,我尝试运行JSDoc的每个文件组件都会收到此错误:

  

相邻的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>

有没有人有过在.vue文件上运行JSDoc的经验?看起来它应该是可能的,但网上的信息很少。

由于

2 个答案:

答案 0 :(得分:1)

我一直在使用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

答案 1 :(得分:1)

我编写了一个简单的@component插件,该插件有助于使用@jsdoc解析.vue文件。它还为他们生成预览。签出:https://github.com/SoftwareBrothers/better-docs

相关问题