vue自定义指令的方法有哪些

vue
573
2021/3/30 10:28:54
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在vue中自定义指令的方法有:语法:Vue.directive(id, definition);1.自定义全局指令;2.自定义私有指令;

vue自定义指令的方法有哪些

在vue中自定义指令的方法有以下两种

vue自定义指令语法:

Vue.directive(id, definition)

1.自定义全局指令

Vue.directive('focus', {

     bind: function (el) { 

         el.focus()

     },

     inserted: function (el) { 

         el.focus()

     },

     updated: function () { 

     }

 });

2.自定义私有指令

directives: {

    'fontweight': {

        bind: function (el, bingding) {

            el.style.fontWeight = bingding.value;

        }

    },

    'fontsize': function (el, bingding) { 

        el.style.fontSize = parseInt(bingding.value) + 'px';

    }

}


辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: vue如何路由跳转