Created
August 11, 2017 13:30
-
-
Save nadyshalaby/e93626a610bb993b4ca7f89eb15586d9 to your computer and use it in GitHub Desktop.
Vue V-Model On Custom Component // source https://jsbin.com/wocuwir
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>Vue V-Model On Custom Component</title> | |
| </head> | |
| <body> | |
| <div id="app"> | |
| <coupon v-model="coupon" ></coupon> | |
| {{ coupon }} | |
| </div> | |
| <script type="text/x-template" id="coupon"> | |
| <p> | |
| <input type="text" :value="value" @input="updateCode($event.target.value)"/> | |
| </p> | |
| </script> | |
| <script id="jsbin-javascript"> | |
| 'use strict'; | |
| Vue.component('coupon', { | |
| template: '#coupon', | |
| props: ['value'], | |
| methods: { | |
| updateCode: function updateCode(code) { | |
| this.$emit('input', code); | |
| } | |
| } | |
| }); | |
| new Vue({ | |
| el: '#app', | |
| data: { | |
| coupon: "FREEBIE" | |
| } | |
| }); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript"> | |
| Vue.component('coupon',{ | |
| template: '#coupon', | |
| props: ['value'], | |
| methods: { | |
| updateCode(code){ | |
| this.$emit('input', code); | |
| } | |
| } | |
| }); | |
| new Vue({ | |
| el: '#app', | |
| data: { | |
| coupon: "FREEBIE" | |
| } | |
| });</script></body> | |
| </html> |
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
| 'use strict'; | |
| Vue.component('coupon', { | |
| template: '#coupon', | |
| props: ['value'], | |
| methods: { | |
| updateCode: function updateCode(code) { | |
| this.$emit('input', code); | |
| } | |
| } | |
| }); | |
| new Vue({ | |
| el: '#app', | |
| data: { | |
| coupon: "FREEBIE" | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment