Vue pass slot template to extended component

前端 未结 5 1539
Happy的楠姐
Happy的楠姐 2021-01-12 02:24

Is any way to pass a template to extended component? Example, that illustrates the problem:

There is a component named Slide with a template like so:

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 02:40

    (This question is similar to this SO question. I am just gonna share a similar answer I post for that question here.)

    The trick is simple. Basically, when extending, create a new component that registers Parent as a local component.

    Demo: https://jsfiddle.net/jacobgoh101/omjgmb3f/

    const Slide = Vue.extend({
      components: {
        Parent
      },
      template: `
      
        
    I am a slot
    ` }); new Slide().$mount('#container')

提交回复
热议问题