关于前端:vue-自定义指令

6次阅读

共计 309 个字符,预计需要花费 1 分钟才能阅读完成。

自定义指令

// 自定义指令
Vue.directive('focus',{bind(el,binding){console.log(el,binding,'---------')
    },
    inserted(el){el.focus()
        console.log(el,'++++++++')
    }
})
Vue.component('ComponentA',{template:'<div><input type="text"v-focus /></div>'})
var vm = new Vue({
    el:"#app",
    data:{msg:'sxq'},
    template:'<div><ComponentA></ComponentA></div>'
})
正文完
 0