Skip to content

Instantly share code, notes, and snippets.

@nadyshalaby
Created August 11, 2017 13:30
Show Gist options
  • Save nadyshalaby/e93626a610bb993b4ca7f89eb15586d9 to your computer and use it in GitHub Desktop.
Save nadyshalaby/e93626a610bb993b4ca7f89eb15586d9 to your computer and use it in GitHub Desktop.
Vue V-Model On Custom Component // source https://jsbin.com/wocuwir
<!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>
'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