Pat*_*ros 56 blade vue.js laravel-blade
我需要在vue.js文件中插入注释以供将来引用,但是我没有在文档中找到你如何做到这一点.
我已经试过//,/**/,{{-- --}},和{# #},但他们都不工作.
我正在使用Laravel的刀片.所以这是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>
Run Code Online (Sandbox Code Playgroud)
有谁知道如何插入评论和/或如何评论代码片段?
Bil*_*ell 105
您希望<template>在您的情况下在标记中使用标准HTML注释.它们也会从输出中被剥离,这很好.
<!-- Comment -->
Run Code Online (Sandbox Code Playgroud)
Vai*_*pal 17
正如Bill Criswell所说,我们可以使用HTML注释语法.
<!-- Comment -->
Run Code Online (Sandbox Code Playgroud)
但是,它也可以在模板标签之外工作, 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>
Run Code Online (Sandbox Code Playgroud)
小智 16
我注意到当你在标签内时你不能评论:
<!-- make sure it is outside a tag -->
<autocomplete
<!-- you can't place the comment out in here -->
>
</autocomplete>
Run Code Online (Sandbox Code Playgroud)
Mic*_*oka 12
以下技巧与其说是关于注释(如在文档中)代码本身,不如说是关于允许您在开发过程中暂时跳过代码块。
当注释需要开始和结束标记时,解析器匹配它们的方式可能会很不方便。例如下面的
<!-- I want to comment this <!-- this --> and that -->
Run Code Online (Sandbox Code Playgroud)
将输出and that -->. 相似地/* this will be commented /* and so will this */ but not this */。
我的解决方案是用来v-if="false"指定我想要(暂时)跳过哪些块。
<template>
<div>
Hello
<div v-if="false">
Vue will not process whatever's in here.
</div>
World!
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
请注意,这不应该用来代替正确的注释来记录您的代码。这只是一种对开发过程中想要跳过的块进行更多控制的便捷方法。
小智 11
如果它对您的项目有用,您可以将纯文本放在模板上方,无需装饰。当您渲染组件时,它会被完全忽略。
This is some documentation about this component
- some
- info
<template></template>
<script></script>
<style></style>
Run Code Online (Sandbox Code Playgroud)
我刚刚测试过:
<template>
{{ /* this is a comment */ }}
<h1>Hello world</h1>
</template>
Run Code Online (Sandbox Code Playgroud)
Vue Styleguidist 包含最佳实践并展示了如何注释组件的示例。 https://vue-styleguidist.github.io/docs/Documenting.html#code-comments
不过一般...
在模板或 HTML 部分使用 HTML 注释
<!-- Comment -->
Run Code Online (Sandbox Code Playgroud)
在脚本部分使用 Javascript 注释
// Comment
/* Comment */
Run Code Online (Sandbox Code Playgroud)
在样式部分使用 CSS 注释
/* comment */
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49384 次 |
| 最近记录: |