javascript - 如何使用`h`创建一个非空评论节点?
问题描述
以下代码将生成一个空的注释节点,即<!---->
.
如何生成非空评论节点,例如<!-- Foo -->
使用h
?
export default {
render(h) {
return h(null)
},
}
解决方案
选项 1:h(null)
使用字符串作为第二个参数
export default {
render(h) {
return h(null, 'This is a comment') // <!--This is a comment-->
},
}
选项 2:h(Comment)
使用字符串作为第二个参数
import { h, Comment } from 'vue' // Vue 3
export default {
render() {
return h(Comment, 'This is a comment') // <!--This is a comment-->
},
}
选项 3:createCommentVNode()
使用字符串作为参数
import { createCommentVNode } from 'vue' // Vue 3
export default {
render() {
return createCommentVNode('This is a comment') // <!--This is a comment-->
},
}
推荐阅读
- sql - Spark SQL CTE在查询中忽略命名空间
- flutter - 在颤动中返回并显示列表中的项目数
- google-cloud-platform - 对 Google API 的请求停止工作,我该如何调试该问题?
- c++ - KTX 图像文件可以是立方体贴图数组吗?
- python - 用于查找文档之间文本相似性的 keras LSTM 层的维数错误
- asp.net - MiniProfiler MVC SQL 计时不显示
- css - *ngFor 不同类的元素
- c# - C# Convert.ToBase64String VS PHP base64_encode
- html - 引导程序;正确格式化行/节背景
- amazon-web-services - 在 Lambda 中使用 AWS 开发工具包函数