我建立自定义的指令,它存储在它自己的文件vuejs定制指令似乎没有注册
autosize.js,它看起来像这样:
import Vue from 'vue'
import autosize from 'autosize'
Vue.directive('autosize', {
bind: function() {
console.log('autosize bind')
var self = this
Vue.nextTick(function() {
autosize(self.el)
})
},
update: function(value) {
console.log('autosize update')
var self = this
Vue.nextTick(function() {
self.el.value = value
autosize.update(self.el)
})
},
unbind: function() {
autosize.destroy(this.el)
}
})
我使用它的文件组件内部并导入这样的:
import Autosize from 'components/directives/autosize.js'
注册这样的:
directives: {
Autosize
}
在我的文件组件我尝试使用这样的:
<textarea v-autosize="input" :value="input" @input="update" class="form-control">{{input}}</textarea>
自动调整是应该使textarea的成长插件,当我测试增加更多的文字ofcourse没有任何反应。但是似乎它不自动调整失败的工作,但也许我错过了一些东西,甚至没有这些得到印刷:
console.log('autosize bind')
console.log('autosize update')
当我动态创建的组件。
任何人都有一个想法,我已经错过了,使指令没有约束力或更新?
在Vue公司2,用类似这样的代码工作典型的方法是使用一个包装组件。但是就这条指令而言,'el'作为指令中的一个参数被传入,它不可用'this'(或'this'重命名为'self')。 – Bert