I
I
Igor Che2017-07-06 14:19:56
Vue.js
Igor Che, 2017-07-06 14:19:56

How to call an instance method from a directive?

How to call an instance method from a directive without calling it by name (app_ctrl.updateVal())? You can't use this because this points to input.
I want to bind this directive to different instances, I don't want to duplicate it.
Here is the stripped down code:

Vue.directive('picker', {
        inserted: function (el, binding) {
            $.mask.definitions['H']='[0-9]';
            $(el).mask("HH:HH", {
                completed: function(){
                    // Метод который хочу вызвать
                    this.updateVal(binding.value['i'], binding.value['day'], this.val())
                }
            });
        }
    });

app_ctrl = new Vue({
        delimiters: ['{*', '*}'],
        el: '#controlapp',
        data: {
            data: [],
            obj_name: '',
        },

        methods:{
             // Метод который хочу вызвать
             updateVal : function (i, day, time) {
                console.log(i, day, time);
                this.data[i][day] = time;
            },
        }
    });

<table>
<tbody v-cloak>
<tr v-for="(row, i) in data" class="row body">
<td v-bind:disabled="!row.mon_from">
    <input type="text" v-model="row.mon_from" v-picker="{i: i, day: 'mon_from'}">
</td>
</tr>
</tbody>
</table>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question