宝哥软件园

解释vue中v-on绑定自定义事件的例子

编辑:宝哥软件园 来源:互联网 时间:2021-08-30

官网vue中v-on绑定自定义事件的个人理解

对官网示例做了一些修改,如下图所示:

!doctype html lang=' en ' head metacarset=' utf-8 ' title v-on binding custom event/title script src=' http : vue . js '/script/head dydivided=' app ' p { { total } }/p button-counter v-: Inc='父1'/button-counter button-counter v-: Inc='父2 '/button-counter v-: Inc='父1 '/button-counter这个。$ emit(' increment ');这个。$ emit(' incr ');这个。$ emit(' Inc ');} } });new Vue({ El : ' # app },data: { total: 0 },methods: {父1: function () { this.total=1 },父2: function(){ this . total-=1 } })/script/body/html

单击第一个按钮,浏览器的执行顺序如下所示:

第一步:点击第一个按钮,执行子组件的子功能

第二步:分别触发按钮中的事件$ emit(' ');

第三步,监控v-:增量事件,

步骤4,执行父组件监控事件父1;子组件的;

以上vue中v-on绑定自定义事件的示例说明,都是边肖分享给大家的内容,希望能给大家一个参考和支持。

更多资讯
游戏推荐
更多+