【发布时间】:2021-04-23 11:07:53
【问题描述】:
我目前有这样的事情:
<q-input v-model="value" label="Some Label" v-bind="getDefaults('someId')" />
getDefaults() 在哪里:
function getDefaults (id) {
return {
'id': id,
'clearable': true,
'lazy-rules': true,
'outlined': true,
'class': 'form-padding'
// more props/parameters
}
}
现在,我想将 v-bind 转换为自定义指令。
export const sampleDirective = {
inserted: function (el, binding) {
// this doesn't work
el.class += 'form-padding'
// how to set id from here
// and how to set the props as well (like ```clearable```, ```lazy-rules```, etc)?
}
}
那么如何从自定义指令中设置这些参数/道具,以便我可以这样调用它:
<q-input v-model="value" label="Some Label" v-sampleDirective="{ id: 'someId' }" />
谢谢!
【问题讨论】:
标签: vue.js vue-directives