Skip to content

Instantly share code, notes, and snippets.

@rodrigopedra
Last active November 20, 2018 12:52
Show Gist options
  • Save rodrigopedra/1a28a7219fe9c882823eacdfb90d1486 to your computer and use it in GitHub Desktop.
Save rodrigopedra/1a28a7219fe9c882823eacdfb90d1486 to your computer and use it in GitHub Desktop.
Render Vue child components with Laravel Blade
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
<parent-component inline-template>
<ul>
@foreach(range(1, 3) as $i)
<child-component index="{{ $i }}" :value="value" @mounted="handleChildMounted"></child-component>
@endforeach
</ul>
</parent-component>
</div>
<script>
Vue.component('parent-component', {
data: function () {
return { value: 'secret-value' };
},
methods: {
handleChildMounted: function (index) {
alert('Child #' + index + ' was mounted');
}
}
});
Vue.component('child-component', {
props: ['index', 'value'],
template: '<li>@{{ index }} - @{{ value }}</li>',
mounted: function () {
this.$emit('mounted', this.index);
}
});
new Vue( { el : '#app' } );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment