Guest User

Untitled

a guest
May 25th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. // HTML
  2. <div id="app">
  3. <multi-choice :items="myItems" @selected="alert($event)"></multi-choice>
  4. <multi-choice :items="myItems" @selected="sayIsCool"></multi-choice>
  5. </div>
  6.  
  7. // JavaScript
  8. const multiChoice = {
  9. template: '<div class="multi-choice"><span v-for="item in items" @click="select(item)">{{ item }}</span></div>',
  10. props: ['items'],
  11. methods: {
  12. select(item) {
  13. this.$emit('selected', item);
  14. }
  15. }
  16. };
  17.  
  18. new Vue({
  19. el: "#app",
  20. data() {
  21. return {
  22. myItems: [
  23. 'Homer',
  24. 'Marge',
  25. 'Bart'
  26. ],
  27. }
  28. },
  29. components: {
  30. multiChoice: multiChoice
  31. },
  32. methods: {
  33. sayIsCool(item) {
  34. alert(item + ' is cool!')
  35. }
  36. }
  37. })
Add Comment
Please, Sign In to add comment