code.js 459 B

12345678910111213141516171819202122232425262728293031
  1. window.Event = new Vue();
  2. Vue.component('coupon', {
  3. methods: {
  4. onCouponApplied() {
  5. Event.$emit('applied');
  6. }
  7. },
  8. template: `
  9. <input placeholder="Enter your coupon code" @blur="onCouponApplied" />
  10. `,
  11. });
  12. const app = new Vue({
  13. el: '#root',
  14. data: {
  15. couponApplied: false,
  16. },
  17. created() {
  18. Event.$on('applied', this.onCouponApplied);
  19. },
  20. methods: {
  21. onCouponApplied() {
  22. this.couponApplied = true;
  23. }
  24. }
  25. });