Last active
November 20, 2018 12:52
-
-
Save rodrigopedra/1a28a7219fe9c882823eacdfb90d1486 to your computer and use it in GitHub Desktop.
Render Vue child components with Laravel Blade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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