vue

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

发布于 2021-01-11 17:03:12
关注者
0
被浏览
515
6 个回答
  • 面试哥
    面试哥 2021-01-12
    为面试而生,有面试问题,就找面试哥。
    <template comments>
    <!--我是注释内容-->
    </template>
    <script>
    export default {
        comments: true;
    }
    </script>
  • 面试哥
    面试哥 2021-01-12
    为面试而生,有面试问题,就找面试哥。

    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

  • 面试哥
    面试哥 2021-01-12
    为面试而生,有面试问题,就找面试哥。
    <template comments>
      ...
    </template>
  • 面试哥
    面试哥 2021-01-12
    为面试而生,有面试问题,就找面试哥。
    ... <script> import... export default{ comments: true, ... } </script>
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看