如何给IView中的输入框增加一个自定义指令?

【需求】:进入某个界面,输入框自动获取焦点。
【问题】:使用iView框架中的输入框,如何给这个输入框添加一个自定义指令?
【代码】:

iView中的输入框组件:
<template>
    <Input v-model="value14" v-focus placeholder="Enter something..." clearable style="width: 200px"></Input>
</template>

自定义指令:
Vue.directive('focus', {
    inserted: function (el) {
        console.log('el-->',el);        // el.focus();
    }
});

【问题描述】:现在这个el操作的是input的父级元素,我要如何才能操作当前这个元素的子元素?

https://img4.mukewang.com/5b4b53bb00016ad408000155.jpg


慕田峪4524236
浏览 1515回答 2
2回答

米脂

找到iview中input组件,从底层自定义就好,或者自己自己写一个input组件

梵蒂冈之花

iview api有autofocus&nbsp;&nbsp;&nbsp;directives:&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;focus:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inserted:&nbsp;function(el,&nbsp;binding,&nbsp;vnode)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vnode.child.$refs.input.autofocus=true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}, &nbsp;&nbsp;&nbsp;&nbsp;}, &nbsp;&nbsp;&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP