my-blog icon indicating copy to clipboard operation
my-blog copied to clipboard

[Vssue]vue2-4

Open shenghy opened this issue 5 years ago • 6 comments

https://jspang.com/posts/2017/04/09/vue2-4.html

shenghy avatar Apr 19 '19 08:04 shenghy

app.$on('reduce', function () { console.log("我被减了"); this.message--; }); app.$once('reduceOnce', function () { console.log('只执行一次的方法'); this.message--; }); //如果按钮在作用域外部,可以利用$emit来执行。 function reduce() { app.$emit('reduce'); } function reduceOnce() { app.$emit('reduce'); //app.$emit('reduceOnce'); } 实例事件中,这样子始终可以执行减,$once是什么原理呢

blackHuLi avatar Jun 17 '19 14:06 blackHuLi

@blackHuLi

app.$on('reduce', function () { console.log("我被减了"); this.message--; }); app.$once('reduceOnce', function () { console.log('只执行一次的方法'); this.message--; }); //如果按钮在作用域外部,可以利用$emit来执行。 function reduce() { app.$emit('reduce'); } function reduceOnce() { app.$emit('reduce'); //app.$emit('reduceOnce'); } 实例事件中,这样子始终可以执行减,$once是什么原理呢

你应该是粗心的把最后一个$emit调用注释错了。reduceOnce方法,外部调用应该是app.$emit('reduceOnce');

zxiao0216 avatar Jun 19 '19 01:06 zxiao0216

@zxiao0216

@blackHuLi

app.$on('reduce', function () { console.log("我被减了"); this.message--; }); app.$once('reduceOnce', function () { console.log('只执行一次的方法'); this.message--; }); //如果按钮在作用域外部,可以利用$emit来执行。 function reduce() { app.$emit('reduce'); } function reduceOnce() { app.$emit('reduce'); //app.$emit('reduceOnce'); } 实例事件中,这样子始终可以执行减,$once是什么原理呢

你应该是粗心的把最后一个$emit调用注释错了。reduceOnce方法,外部调用应该是app.$emit('reduceOnce');

不是的咯,这个是故意去注释掉的,大概清楚了,app.$once('reduceOnce', function () 相当于挂载一个方法,通过外部调用,$emit()来做外部调用

blackHuLi avatar Jun 19 '19 06:06 blackHuLi

{{num}}

app.$on('reduce',function () { this.num--; }); function reduce() { app.$emit('reduce'); } 作者教程使用的vue是2.1.3,此时我上面的写法是正确的。而在vue2.6.10出现reduce未声明的提示.

qinZhenGitHub avatar Sep 08 '19 12:09 qinZhenGitHub

slot和props传值有什么区别

用props不是更简单吗

xmylcn avatar Nov 07 '19 03:11 xmylcn

function tick(){ vm.message="update message info "; vm.$nextTick(function(){ console.log('message更新完后我被调用了'); }) }

这个我并没有去更新message的值,控制台也会打印

SabrinaLiii avatar Nov 11 '19 03:11 SabrinaLiii