Skip to content

Commit f818c09

Browse files
author
Kerstens Maxim
authored
Explained the second 'vm' argument
1 parent eca2be4 commit f818c09

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,18 @@ You can subscribe a vue instance to a single standard channel if needed and defi
5656
var vm = new Vue({
5757
channel: 'blog',
5858
echo: {
59-
'BlogPostCreated': payload => {
59+
'BlogPostCreated': (payload, vm) => {
6060
console.log('blog post created', payload);
6161
},
62-
'BlogPostDeleted': payload => {
62+
'BlogPostDeleted': (payload, vm) => {
6363
console.log('blog post deleted', payload);
6464
}
6565
}
6666
});
6767
```
6868

69+
Since the scope of `this` would be the same as the scope where you declare your Vue instance a second parameter is added to these locally registered events. This parameter is a direct reference to your Vue instance, you can make any changes you need through there.
70+
6971
#### Subscribing to channels
7072

7173
Laravel Echo allows you to subscribe to: normal, private and presence channels.
@@ -79,10 +81,10 @@ If you would like to subscribe to a private channel instead, prefix your channel
7981
var vm = new Vue({
8082
channel: 'private:team.1',
8183
echo: {
82-
'BlogPostCreated': payload => {
84+
'BlogPostCreated': (payload, vm) => {
8385
console.log('blog post created', payload);
8486
},
85-
'BlogPostDeleted': payload => {
87+
'BlogPostDeleted': (payload, vm) => {
8688
console.log('blog post deleted', payload);
8789
}
8890
}
@@ -97,7 +99,7 @@ If you would like to subscribe to presence channel instead, prefix your channel
9799
var vm = new Vue({
98100
channel: 'presence:team.1.chat',
99101
echo: {
100-
'NewMessage': payload => {
102+
'NewMessage': (payload, vm) => {
101103
console.log('new message from team', payload);
102104
}
103105
}
@@ -112,10 +114,10 @@ If there's a scenario where you want to listen to events after certain condition
112114
var vm = new Vue({
113115
channel: 'private:team.1',
114116
echo: {
115-
'BlogPostCreated': payload => {
117+
'BlogPostCreated': (payload, vm) => {
116118
console.log('blog post created', payload);
117119
},
118-
'BlogPostDeleted': payload => {
120+
'BlogPostDeleted': (payload, vm) => {
119121
console.log('blog post deleted', payload);
120122
}
121123
},

0 commit comments

Comments
 (0)