How to comment code in a vue.js file?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to comment code in a vue.js file?



I have the need to insert a comment inside a vue.js file for future references, but I don't find how you do this in the docs.



I have tried //, /**/, {{-- --}}, and {# #}, but none of them seem to work.


//


/**/


{{-- --}}


{# #}



I am using Laravel's blade. So this is the sample_file.vue:


sample_file.vue


<template>
<div class="media">

<like-button :post="post" v-if="post.likedByCurrentUser === false && "></like-button> {{--I want to comment this but I get an error from the gulp watch: post.canBeLikedByCurrentUser === true--}}

<div class="media-left">
<a href="#">
<img class="media-object" v-bind:src="post.user.avatar" v-bind:title="post.user.name + ' image from Gravatar'">
</a>
</div>
<div class="media-body">
<strong>{{ post.user.name }}</strong>
<p>{{post.body}}</p>
<p>{{post.likeCount}} {{ pluralize('like', post.likeCount) }}</p>
</div>
</div>
</template>



Does anyone know how to insert a comment and / or how to comment pieces of code?





If you're looking for multi-line commenting, the standard html comment will work: <!-- -->. But it sounds like you're looking for inline commenting?
– Adam
Dec 19 '16 at 18:43




<!-- -->





Ahh, I forgot to try that. It is indeed HTML code! Thnx
– Pathros
Dec 19 '16 at 19:12


HTML




3 Answers
3



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.


<template>


<!-- Comment -->





That did the trick
– Pathros
Dec 19 '16 at 19:13



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>





This results in "Unexpected token (1:1)" with Vue 2.5.13.
– Alen Siljak
Dec 31 '17 at 15:54





I used to comment outside the supported root tags and found it to cause issues depending on the content of the comments. I wish vue supported comments outside the root tags because it's the most sensible place to create READMEs and such, but oh well.
– aaaaaa
Jun 20 at 15:45



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.

...






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived