注释掉Vue模板元素的一部分 [英] Comment out a part of Vue template element

查看:245
本文介绍了注释掉Vue模板元素的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时需要注释掉某些元素属性而不必记住它,以便在某些测试后快速恢复它。

Sometimes it is needed to comment out some element attribute without having to remember it in order to restore it quickly after some tests.

使用以下方法可以注释掉整个元素HTML注释语法

Commenting out whole element is achievable with HTML commenting syntax

<div>
    <!-- <h2>Hello</h2> -->
    <span>hi</span>
</div>

但是,这不适用于单个属性(导致呈现错误)

However this won't work with a single attribute (causes rendering error)

<my-comp id="my_comp_1"
         v-model="value"
         <!-- :disabled="!isValid" -->
         @click="handleClick">
</my-comp>

我以前可以看到和使用的最佳方法是通过复制整个元素和设置来进行标签备份 v-if = false 为此(或注释掉整个复制的元素),并继续尝试原始的元素

The best approach I could see and used before was to make a tag backup by copying whole element and settings v-if="false" for it (or comment out whole copied element) and continue to experiment with original one

推荐答案

我认为您不能在组件标签中放置HTML注释,出于同样的原因,您不能在HTML元素开始标签中放置注释。两种情况下都不是有效的标记。我认为,最接近的注释应该放在引号中:

I don't think you can put an HTML comment inside a component tag, for much the same reason you can't put comments inside an HTML element opening tag. It's not valid markup in either situation. I think the closest you could come would be to place the comment in the quotes:

:disabled="// !isValid"

与以下内容具有相同的作用:

Which would have the same effect as:

:disabled=""

取决于您的组件可以解决丢失的值,这可能满足您的需求。

Depending on whether your component can handle that value being missing, that might fit your needs.

这篇关于注释掉Vue模板元素的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆