Skip to content

Commit

Permalink
fix: extend Vue parent with options to support accessing root. with V…
Browse files Browse the repository at this point in the history
…CA (#1661)
  • Loading branch information
lmiller1990 committed Aug 24, 2020
1 parent 8e9dda3 commit f78f817
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/create-instance/create-instance.js
Expand Up @@ -123,7 +123,13 @@ export default function createInstance(
createChildren(this, h, options)
)
}
const Parent = _Vue.extend(parentComponentOptions)

// options "propsData" can only be used during instance creation with the `new` keyword
const { propsData, ...rest } = options // eslint-disable-line
const Parent = _Vue.extend({
...rest,
...parentComponentOptions
})

return new Parent()
}
18 changes: 18 additions & 0 deletions test/specs/mount.spec.js
Expand Up @@ -419,6 +419,24 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
expect(wrapper.html()).toEqual('<div>composition api</div>')
})

it('allows accessing $root with composition api plugin', () => {
const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(CompositionAPI)
const store = new Vuex.Store({
state: {
msg: 'msg'
}
})
const Comp = {
setup(props, ctx) {
return () => createElement('div', ctx.root.$store.state.msg)
}
}
const wrapper = mount(Comp, { localVue, store })
expect(wrapper.html()).toEqual('<div>msg</div>')
})

itDoNotRunIf.skip(
vueVersion >= 2.5,
'throws if component throws during update',
Expand Down

0 comments on commit f78f817

Please sign in to comment.