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

Provided values in mixin are not accessible #9213

Closed
Tidyzq opened this issue Dec 17, 2018 · 4 comments
Closed

Provided values in mixin are not accessible #9213

Tidyzq opened this issue Dec 17, 2018 · 4 comments
Labels

Comments

@Tidyzq
Copy link

Tidyzq commented Dec 17, 2018

Version

2.5.21

Reproduction link

https://codepen.io/anon/pen/oJLdMN

Open the link and see the error message in dev console.

Steps to reproduce

Create two mixins with a provide object using Symbol as it's key field. Then assign these mixins to a component.

What is expected?

The child component can access two provide object without any error.

What is actually happening?

The child component can only access the last provide object, while the first one is undefined.


Diving into the source code, the reason of this issue is that Vue uses Object.keys to iterate over the provide object while merging mixins. However, Object.keys won't return Symbol keys. see the code.
Maybe we should use for ... in loop, which will iterate through Symbol keys correctly.

@posva
Copy link
Member

posva commented Dec 17, 2018

It doesn't seem to be related to Symbols but rather using provide in a mixin as this also fails:

var provideMixin1 = {
  provide: {
    foo: 'it is foo'
  }
}

var Parent = {
  mixin: [
    provideMixin1,
  ],
  template: '<div><slot /></div>'
}

var Child = {
  inject: ['foo'],
  template: '<div>foo: {{ foo }} bar:</div>',
}

new Vue({
  components: {
    Parent,
    Child,
  },
  template: '<parent><child /></parent>'
}).$mount('#app')

@posva posva added the bug label Dec 17, 2018
@posva posva changed the title use provide with Symbol in mixins got error Provided values in mixin are not accessible Dec 17, 2018
@Tidyzq
Copy link
Author

Tidyzq commented Dec 17, 2018

I'm sorry that I got a typo...
It should be mixins rather than mixin, but the Symboled keys still can't be treated correctly.
https://codepen.io/anon/pen/NeroQJ

@yyx990803
Copy link
Member

This is addressed by #7926 (pending merge for next minor)

@posva
Copy link
Member

posva commented Dec 17, 2018

Ups, my bad, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants