Skip to content

[vue] vue渲染模板时怎么保留模板中的HTML注释呢? #508

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

[vue] vue渲染模板时怎么保留模板中的HTML注释呢?

Activity

yalishizhude

yalishizhude commented on Jun 28, 2019

@yalishizhude
<template comments>
  ...
</template>
zboMa

zboMa commented on Jul 1, 2019

@zboMa
<template comments>
  ...
</template>
naokimidori

naokimidori commented on Jul 4, 2019

@naokimidori
<template comments>
...
<template>
girlfighting

girlfighting commented on Jul 5, 2019

@girlfighting

janwenGighub

janwenGighub commented on Jul 12, 2019

@janwenGighub
...
finghtingjie

finghtingjie commented on Jul 15, 2019

@finghtingjie

<template comments> ... <template>

jianhui-sha

jianhui-sha commented on Jul 19, 2019

@jianhui-sha

...

cxrloveuu

cxrloveuu commented on Jul 25, 2019

@cxrloveuu

设置comments属性,官网默认为舍弃注释

GShJZhY

GShJZhY commented on Jul 26, 2019

@GShJZhY
... <script> import... export default{ comments: true, ... } </script>
TKBnice

TKBnice commented on Sep 29, 2019

@TKBnice

注释必须位于要保留的根元素内。
comments: true 属性不适于单文件属性

censek

censek commented on Oct 12, 2019

@censek
<template comments>
<!--我是注释内容-->
</template>
<script>
export default {
    comments: true;
}
</script>
XiaoLin-029

XiaoLin-029 commented on Jul 14, 2020

@XiaoLin-029

comments设为true,默认false,设为true之后将会保留且渲染模块中的HTML注释,

dianjie

dianjie commented on Aug 12, 2020

@dianjie

Vue默认舍弃注释,可以通过设置comments来开启,相关文档

<template comments>
	<div>
		<!--我是注释内容-->
	</div>
</template>

注释一定要在根元素之内

<template comments>
	<!--我是注释内容-->
	<div></div>
</template>

这样注释是不生效的。这是vue-loader提供的支持

或者

new Vue({
    el: "#app",
    comments: true
});

注意:在单文件组件设置是不生效的

<script>
    export default {
    	comments: true
    }
</script>

相关issue

liaoxueqing

liaoxueqing commented on Jan 31, 2024

@liaoxueqing

1.使用注释: 在 Vue 模板中,可以使用 注释,这种注释会被保留在渲染后的 HTML 中。
2.使用v-pre指令: 你还可以使用 v-pre 指令,该指令告诉 Vue 跳过这个元素和它的所有子元素的编译过程。这样,元素中的所有内容(包括注释)都会原封不动地保留在渲染后的 HTML 中。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yalishizhude@haizhilin2013@dianjie@liaoxueqing@finghtingjie

        Issue actions

          [vue] vue渲染模板时怎么保留模板中的HTML注释呢? · Issue #508 · haizlin/fe-interview