Skip to content

Instantly share code, notes, and snippets.

@laracasts
Created January 9, 2017 18:16
Show Gist options
  • Save laracasts/37117786ec23bfacf391d81c2cefa35b to your computer and use it in GitHub Desktop.
Save laracasts/37117786ec23bfacf391d81c2cefa35b to your computer and use it in GitHub Desktop.

Revisions

  1. Laracasts created this gist Jan 9, 2017.
    27 changes: 27 additions & 0 deletions vue-custom-input-component-exercise.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    Vue.component('coupon', {
    props: ['code'],

    template: `
    <input type="text"
    :value="code"
    @input="updateCode($event.target.value)"
    ref="input">
    `,

    methods: {
    updateCode(code) {
    // Atttach validation + sanitization here.

    this.$emit('input', code);
    }
    }
    });


    new Vue({
    el: '#app',

    data: {
    coupon: 'FREEBIE' // Maybe from DB or querystring.
    }
    });