vue.js - `render` 函数没有替换插槽内容

标签 vue.js vuejs2 vue-component

我使用的是vue 2.0。

我想生成这个模板:

<Poptip placement="right" width="400">
    <Button type="ghost">click 激活</Button>
    <div class="api" slot="content">my content</div>
</Poptip>

使用渲染函数:

render: (h, params) => {
  return h('Poptip', {
    props: {
      placement: 'right'
    }
  }, [
    h('Button', {
      props: {
        type: 'ghost'
      }
    }, 'Edit'),
    h('div', {
      props: {
        slot: 'content'
      }
    }, 'My content')
  ])
}

使用模板效果非常好。但是,当我使用 render 函数时,插槽的内容不会替换为我的内容。

最佳答案

您正在指定一个名为 slotprop,其值为 content:

h('div', {
  props: {
    slot: 'content'
  }
}, 'My content')

要简单地指定一个名为contentslot:

h('div', {
  slot: 'content'
}, 'My content')

See the documentation.

关于vue.js - `render` 函数没有替换插槽内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45763526/

相关文章:

javascript - 在vue js中创建treeview - 树的深度未知 - 修改DOM

javascript - 在vuejs中使用 `id`时,如何获取 `cname`值作为选项值和 `v-select`作为选项标签?

django - 使用 django 开发和部署 Vuejs 应用程序

vue.js - 父子vue之间的异步生命周期

javascript - 如何在vuex store中导入本地静态图片

javascript - 不向需要参数的方法传递参数

vue.js - VeeValidate,确认规则不适用于 ValidationProvider

javascript - 在循环底部创建新的 Vue 组件

vue.js - 每 5 秒设置和更改图像 - 在 vue 组件中将 setInterval 放在哪里?

vue.js - VueJS : Textarea input binding