Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

doesn't seem to work in a v-for list rendering #2

Closed
didamaran opened this issue Oct 10, 2016 · 3 comments
Closed

doesn't seem to work in a v-for list rendering #2

didamaran opened this issue Oct 10, 2016 · 3 comments

Comments

@didamaran
Copy link

while it's working for me in different components, it doesnt in a list rendered on the basis of an array by v-for.

@tthallos
Copy link
Owner

tthallos commented Nov 2, 2016

Did you mean this?

<div v-for="item in items">
  <textarea v-autosize="item">{{item}}</textarea>
</div>

@didamaran
Copy link
Author

exactly

this is how i implemented the directive:

Vue.directive('autosize', {
bind: function() {
    autosize(this.el);
},

update: function(value) {
    this.el.value = value;
    autosize.update(this.el);
},

unbind: function() {
    autosize.destroy(this.el);
}
});

in a component it works like this:

<textarea v-autosize="nunote.text" v-model="nunote.text">{{nunote.text}}</textarea>

in the same component in a v-for-loop it fails:

<tr v-for="item in positionen">
    <td>
        <textarea v-autosize="item.note" v-model="item.note">{{item.note}}</textarea>
    </td>
</tr>

I ran into this with other plugins / functions too and it seems that its due to the fact, that those dom elements get inserted into the page dynamically (after the app has been started up).

in jquery you're able to address this with on(...). but how do you handle this in vue? i tried to modify the directive like this:

Vue.directive('autosize', {
  bind: function() {
    Vue.nextTick(function() {
      autosize(this.el);
    })
  },

update: function(value) {
  this.el.value = value;
  Vue.nextTick(function() {
    autosize(this.el);
  })
},

unbind: function() {
    autosize.destroy(this.el);
}
});

but it doesnt do the trick either

@tthallos
Copy link
Owner

tthallos commented Nov 2, 2016

I use same way to fix it, you can see my commit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants