Skip to content

Commit f78f817

Browse files
authored
fix: extend Vue parent with options to support accessing root. with VCA (vuejs#1661)
1 parent 8e9dda3 commit f78f817

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/create-instance/create-instance.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ export default function createInstance(
123123
createChildren(this, h, options)
124124
)
125125
}
126-
const Parent = _Vue.extend(parentComponentOptions)
126+
127+
// options "propsData" can only be used during instance creation with the `new` keyword
128+
const { propsData, ...rest } = options // eslint-disable-line
129+
const Parent = _Vue.extend({
130+
...rest,
131+
...parentComponentOptions
132+
})
127133

128134
return new Parent()
129135
}

test/specs/mount.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
419419
expect(wrapper.html()).toEqual('<div>composition api</div>')
420420
})
421421

422+
it('allows accessing $root with composition api plugin', () => {
423+
const localVue = createLocalVue()
424+
localVue.use(Vuex)
425+
localVue.use(CompositionAPI)
426+
const store = new Vuex.Store({
427+
state: {
428+
msg: 'msg'
429+
}
430+
})
431+
const Comp = {
432+
setup(props, ctx) {
433+
return () => createElement('div', ctx.root.$store.state.msg)
434+
}
435+
}
436+
const wrapper = mount(Comp, { localVue, store })
437+
expect(wrapper.html()).toEqual('<div>msg</div>')
438+
})
439+
422440
itDoNotRunIf.skip(
423441
vueVersion >= 2.5,
424442
'throws if component throws during update',

0 commit comments

Comments
 (0)