1

以下代码将生成一个空的注释节点,即<!---->.
如何生成非空评论节点,例如<!-- Foo -->使用h

export default {
  render(h) {
    return h(null)
  },
}
4

1 回答 1

1

选项 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-->
  },
}
于 2021-04-21T03:59:47.807 回答