Created
          January 9, 2017 18:16 
        
      - 
      
- 
        Save laracasts/37117786ec23bfacf391d81c2cefa35b to your computer and use it in GitHub Desktop. 
    vuecasts.com - Custom Input Components exercise.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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. | |
| } | |
| }); | 
thanks @nathanjisaac for advice. I had already spent morning
Awesome @nathanjisaac; now it makes sense!
I spend an hour to try to use code instead of code. Maybe it's changed. Thanks for the comment @nathanjisaac
@nathanjisaac you da man
Thanks @nathanjisaac, It's work use a prop named value instead of code.
The original component should also work with just a small modification:
Vue.component('coupon', {
    // New.
    model: {
        prop: 'code'
    },
    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);
        }
    }
});https://vuejs.org/v2/guide/components-custom-events.html#Customizing-Component-v-model
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Thanks @nathanjisaac for explanation. Stuck on this for a few hours too.