Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HTML
- <div id="app">
- <multi-choice :items="myItems" @selected="alert($event)"></multi-choice>
- <multi-choice :items="myItems" @selected="sayIsCool"></multi-choice>
- </div>
- // JavaScript
- const multiChoice = {
- template: '<div class="multi-choice"><span v-for="item in items" @click="select(item)">{{ item }}</span></div>',
- props: ['items'],
- methods: {
- select(item) {
- this.$emit('selected', item);
- }
- }
- };
- new Vue({
- el: "#app",
- data() {
- return {
- myItems: [
- 'Homer',
- 'Marge',
- 'Bart'
- ],
- }
- },
- components: {
- multiChoice: multiChoice
- },
- methods: {
- sayIsCool(item) {
- alert(item + ' is cool!')
- }
- }
- })
Add Comment
Please, Sign In to add comment