[英]Can't access directive params in vue js
Vue.directive('selecttwo', {
params: ['taskId'],
bind: function () {
var self = this;
$(this.el)
.select2()
.on('change', function () {
self.set(this.value);
if (!this.name.match(/[a-z]/i)) {
console.log('task-id->'+self.params.taskId); // task-id->undefined
}
})
},
});
How can I get the params.taskId
on onchange
event? 如何在
onchange
事件上获取params.taskId
? I already tried this.params.taskId
, but I still get undefined. 我已经尝试过
this.params.taskId
,但是我仍然不确定。
Maybe you can paste your html code,that will help to find issue. 也许您可以粘贴HTML代码,这将有助于发现问题。
I guess your html attribute name is incorrect,in vue,js use "camelCase", but html use "kebab-case",try like this: 我猜您的html属性名称不正确,在vue中,js使用“ camelCase”, 但是 html使用“ kebab-case”,请尝试如下操作:
<span task-id="i am id" v-selecttwo >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.