How to comment code in a vue.js file?

南楼画角 提交于 2019-12-03 04:10:17

You'd want to use standard HTML comments in the <template> tag in your situation. They'll be stripped from the output as well which is nice.

<!-- Comment -->
Vaisakh Rajagopal

As Bill Criswell said we can use HTML comment syntax.

<!-- Comment -->

But, It will work outside the template tag too, comment.vue

<!-- Testing comments, this will work too. -->

<template>
    <!-- This will work too -->

    <div>
        <!-- Html Comments -->
        Hello There!
    </div>
</template>

<style><style>

<!-- Commenting here -->

<script>
    // Commenting only 1 line

    /**
      * Commenting multiple lines
      * Commenting multiple lines
      */
</script>

I have just tested this:

<template>
    {{ /* this is a comment */ }}
    <h1>Hello world</h1>
</template>
Juan Vaca

I noticed that you can't comment when you are inside a tag:

<!-- make sure it is outside a tag -->

<autocomplete
<!-- you can't place the comment out in here -->
>
</autocomplete>
Juan

I'm noob in Vue.js, but // should work because the code is javascript anyway. Looking in the docs I find this example. If you look the first 2 lines of javascript you will see comments with //.

example in javascript linked file:

// Full spec-compliant TodoMVC with localStorage persistence
// and hash-based routing in ~120 effective lines of JavaScript.

...

If you need to comment out an entire html block you can use v-if="false" to "blind" vue to the chunk of code that follows.

<template>
<div>
    Hello
    <div v-if="false">
        This part will be skipped.
    </div>
    World!
</div>
</template>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!