Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ const CustomElement = wrap(Vue, () => import(`MyComponent.vue`))

window.customElements.define('my-element', CustomElement)
```
### Usage with addtional attributes
```js
const vueAttributeBeforeRender = {
i18n:{ locale: 'de' },
foo:{ bar: 'test' },
};

const CustomElement = wrap(Vue, Component, vueAttributeBeforeRender)
```
This will add the attribute to the
```js
new Vue({ // attributes })
```

## Interface Proxying Details

Expand Down
39 changes: 22 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
convertAttributeValue
} from './utils.js'

export default function wrap (Vue, Component) {
export default function wrap (Vue, Component, vueAttributeBeforeRender) {
const isAsync = typeof Component === 'function' && !Component.cid
let isInitialized = false
let hyphenatedPropsList
Expand Down Expand Up @@ -83,23 +83,28 @@ export default function wrap (Vue, Component) {
const self = super()
self.attachShadow({ mode: 'open' })

const wrapper = self._wrapper = new Vue({
name: 'shadow-root',
customElement: self,
shadowRoot: self.shadowRoot,
data () {
return {
props: {},
slotChildren: []
const wrapper = self._wrapper = new Vue(
Object.assign(
vueAttributeBeforeRender, {
name: 'shadow-root',
customElement: self,
shadowRoot: self.shadowRoot,

data () {
return {
props: {},
slotChildren: []
}
},

render (h) {
return h(Component, {
ref: 'inner',
props: this.props
}, this.slotChildren)
}
}
},
render (h) {
return h(Component, {
ref: 'inner',
props: this.props
}, this.slotChildren)
}
})
))

// Use MutationObserver to react to future attribute & slot content change
const observer = new MutationObserver(mutations => {
Expand Down