Skip to content

Instantly share code, notes, and snippets.

@mattstauffer
Last active December 1, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattstauffer/21e9ca43563f204995ad to your computer and use it in GitHub Desktop.
Save mattstauffer/21e9ca43563f204995ad to your computer and use it in GitHub Desktop.
new Vue({
el: '#assignment-creator',
data: {
trainee: {}
},
ready: function () {
this.trainee = TrainRemote.trainee;
}
});
<script>
var TrainRemote = {
trainee: {
id: 5,
name: 'Matt Stauffer'
}
};
</script>
<div id="assignment-creator" v-cloak></div>
@mattstauffer
Copy link
Author

So, my question is: What's the idiomatic (suggested/in-line with Vue styles/practices) way to pass outside data to a Vue instance?

I know if it were a sub-component I'd make it a prop, and then just add it as a property to the <div id="assignment-creator"> element.

But since this is the parent component, is there a better way to pass outside data in (assuming you're not making HTTP calls)?

@adamwathan
Copy link

Or just...

<assignment-creator trainee-id="{{ $trainee->id }}" trainee-name="{{ $trainee->name }}"></assignment-creator>
Vue.component('AssignmentCreator', {
    props: ['traineeId', 'traineeName'],
    // etc.
});

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