code.js 648 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. window.Event = new class {
  2. constructor() {
  3. this.vue = new Vue();
  4. }
  5. fire(event, data = null) {
  6. this.vue.$emit(event, data);
  7. }
  8. listen(event, callback) {
  9. this.vue.$on(event, callback);
  10. }
  11. };
  12. Vue.component('coupon', {
  13. methods: {
  14. onCouponApplied() {
  15. Event.fire('applied');
  16. }
  17. },
  18. template: `
  19. <input placeholder="Enter your coupon code" @blur="onCouponApplied" />
  20. `,
  21. });
  22. const app = new Vue({
  23. el: '#root',
  24. data: {
  25. couponApplied: false,
  26. },
  27. created() {
  28. Event.listen('applied', this.onCouponApplied);
  29. },
  30. methods: {
  31. onCouponApplied() {
  32. this.couponApplied = true;
  33. }
  34. }
  35. });