W
W
wufapexef2018-03-08 18:41:55
Vue.js
wufapexef, 2018-03-08 18:41:55

Why doesn't 2-way binding in the directive work?

There is such a directive and heatplate

Vue.directive('tack', {
  bind (el, binding, vnode) {
    el.style.position = 'fixed'
    el.style.top = binding.value + 'px'
  }
})

<template>
  <div class="hello">
    <input type="text" v-model.lazy="directiveValue">
    {{directiveValue}}
    <h1 v-tack="directiveValue">{{ msg }}</h1>
  </div>
</template>

export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App',
      directiveValue: 0
    }
  }
}

Why is this value not passed to the directive when entering into an input and changing the values ​​of the directiveValue?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-03-08
@wufapexef

The bind hook is called once, when the directive is bound to the element. Use update to process changes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question