Vue

by khamer

HTML

<div id="app">
  <foo v-model="text"></foo>
  <hr>
  <input type="text" v-model="text" @input="input">
</div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

del {
  color: rgba(0, 0, 0, 0.3);
}

Vue

Vue.component('foo', {
  template: `<div>Hello<bar :value="value" @input="v => $emit('input', v)"></bar></div>`,
  props: ['value'],
  methods: {
    input(evt) {
    	console.log('foo got', arguments);
      this.$emit('input', evt);
    },
  },
});

Vue.component('bar', {
  template: `<div>There: <input type="text" :value="value" @input="$emit('input', $event.target.value)"></div>`,
  props: ['value'],
  methods: {
    input(evt) {
      this.$emit('input', evt.target.value);
    },
  },
});

new Vue({
  el: "#app",
  data: {
    text: "Some Text",
  },
  methods: {
    input(evt) {
      this.$emit('input', evt.target.value);
    },
  },
});