Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1655: extend Vue parent with options to support accessing root.$store in Composition API plugin #1661

Merged
merged 1 commit into from Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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