Skip to content

Instantly share code, notes, and snippets.

@e-schultz
Created October 31, 2018 15:39
Show Gist options
  • Select an option

  • Save e-schultz/43a661510abdec293ecf7dc1d44bc47c to your computer and use it in GitHub Desktop.

Select an option

Save e-schultz/43a661510abdec293ecf7dc1d44bc47c to your computer and use it in GitHub Desktop.
Vue Things

Another way we can approach passing data down into Vue, is instead of passing in an object like

<SomeComponent :contact="contact"/>

and in SomeComponent needing to do

{{contact.firstName}}

You can use a v-bind short cut like:

<SomeComponent v-bind="contact"/>

And change the props of SomeComponent to be:

<div>
{{firstName}}
</div>
export default {
 name: 'SomeComponent',
 props: ['firstName','lastName'] // short hand - should make use of the type / required / etc
}

In the component that is calling SomeComponent -- if the contact object is there, and has keys that match firstName and lastName - they will get passed down as props, and in SomeComponent can do

I cover this in more detail in a talk I gave recently, slides here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment