Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f78f817

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

File tree

2 files changed

+25
-1
lines changed
Filter options

2 files changed

+25
-1
lines changed

‎packages/create-instance/create-instance.js

Copy file name to clipboardExpand all lines: packages/create-instance/create-instance.js
+7-1Lines changed: 7 additions & 1 deletion
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

Copy file name to clipboardExpand all lines: test/specs/mount.spec.js
+18Lines changed: 18 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.