vue基础——自定义指令

    科技2022-08-26  100

    vue自定义指令

    可以使用Vue.directive( ‘指令名称’ , {} ) 来定义全局自定义指令也可以使用 directives{ 指令名称 : {} } 来定义局部自定义指令

    全局自定义指令

    <div id="app"> <input type="text" v-focus /> </div> Vue.directive('focus',{ inserted:function(el){ el.focus(); } }); var vm = new Vue({ el:"#app", data:{ msg:"" }, methods:{ } })

    局部自定义指令

    <div id="app"> <input type="text" v-focus /> </div> var vm = new Vue({ el:"#app", data:{ msg:"" }, methods:{ }, //局部指令 directives:{ focus:{ inserted:function(el){ el.focus(); } } } })
    Processed: 0.016, SQL: 9