How to update the data from a vue 2 directive?

1

How can I perform the following procedure to update data from a policy in vue.

var select = Vue.directive('select', {
	twoWay: true,
	bind: function(el, binding, vnode){
		
    // Como acessar op ?????
  	// this.set()
  }
})

new Vue({
	el: '#demo',
    data: function(){
  	return {
    	op: 2
    }
  }
});
select{
  width:200px;
  padding:5px;
 }
<script src="https://unpkg.com/vue/dist/vue.js"></script><divid="demo">
  <p>Opção: {{ op }}</p>
  <select v-select>
    <option v-bind:value="1">1</option>
    <option v-bind:value="2">2</option>
  </select>
</div>
    
asked by anonymous 25.11.2016 / 23:05

1 answer

0

The TwoWay property was removed in version 2 of Vue . The best way to do what you want is to simply use the native Vue.js directive created for this v-model . With it you can update a content from the value of select.

new Vue({
  el: '#demo',
  data: function() {
    return {
      op: 2
    }
  }
});
select {
  width: 200px;
  padding: 5px;
}
<script src="https://unpkg.com/vue/dist/vue.js"></script><divid="demo">
  <p>Opção: {{ op }}</p>
  <select v-model='op'>
    <option v-bind:value="1">1</option>
    <option v-bind:value="2">2</option>
  </select>
</div>
    
06.12.2016 / 01:25