karol-f / vue-custom-element

Vue Custom Element - Web Components' Custom Elements for Vue.js
https://karol-f.github.io/vue-custom-element/
MIT License
1.97k stars 187 forks source link

Allow template syntax for slots #121

Closed dennisbaskin closed 6 years ago

dennisbaskin commented 6 years ago

This PR adds the following functionality (notes taken from docs):

Using Template Tags

To use template tags to add content without necessitating the need for an element wrapper, you can follow the following pattern:

<template slot id="header">My Content</template>

You would need to add the slot attribute (not a vue-slot) and provide an id attribute that matches the name of the slot you wish to add content to.

Passing Custom Elements Inside Slots

When passing custom elements inside of slots, you may get errors that warn about Unknown custom element. There are two ways around this.

  1. Add your custom element to a list of ignored elements in the vue config:

    Vue.config.ignoredElements.push('my-custom-element')
  2. Make sure the elments being inserted into another element are created as custom elements first:

        Vue.customElement('custom-child-one', CustomChildOne)
        Vue.customElement('custom-child-two', CustomChildTwo)
    
        Vue.customElement('custom-parent', CustomParent)
        <custom-parent>
          <template slot id="some-id">
            <custom-child-one></custom-child-one>
            <custom-child-two></custom-child-one>
          </template>
        </custom-parent>
dennisbaskin commented 6 years ago

Referencing issue: https://github.com/karol-f/vue-custom-element/issues/118

karol-f commented 6 years ago

Thanks, will look at it soon!

karol-f commented 6 years ago

Released in @3.1.0 (https://github.com/karol-f/vue-custom-element/releases/tag/v3.1.0). Thanks for the PR!

dennisbaskin commented 6 years ago

Thank you! 😸