You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-8Lines changed: 33 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,17 +60,17 @@ You can subscribe a vue instance to a single standard channel if needed and defi
60
60
var vm =newVue({
61
61
channel:'blog',
62
62
echo: {
63
-
'BlogPostCreated': (payload, vm) => {
63
+
'BlogPostCreated': (payload) => {
64
64
console.log('blog post created', payload);
65
65
},
66
-
'BlogPostDeleted': (payload, vm) => {
66
+
'BlogPostDeleted': (payload) => {
67
67
console.log('blog post deleted', payload);
68
68
}
69
69
}
70
70
});
71
71
```
72
72
73
-
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.
73
+
You can feel free to use `this`inside Your methods.
74
74
75
75
#### Subscribing to channels
76
76
@@ -85,16 +85,41 @@ If you would like to subscribe to a private channel instead, prefix your channel
85
85
var vm =newVue({
86
86
channel:'private:user.1',
87
87
echo: {
88
-
'BlogPostCreated': (payload, vm) => {
88
+
'BlogPostCreated': (payload) => {
89
89
console.log('blog post created', payload);
90
90
},
91
-
'BlogPostDeleted': (payload, vm) => {
91
+
'BlogPostDeleted': (payload) => {
92
92
console.log('blog post deleted', payload);
93
93
}
94
94
}
95
95
});
96
96
```
97
97
98
+
If you need to compute channel name, you should pass `channel` as function.
99
+
100
+
```js
101
+
var vm =newVue({
102
+
channel() {
103
+
return`private:user.${this.userId}`
104
+
},
105
+
echo: {
106
+
'BlogPostCreated': (payload) => {
107
+
console.log('blog post created', payload);
108
+
},
109
+
'BlogPostDeleted': (payload) => {
110
+
console.log('blog post deleted', payload);
111
+
}
112
+
},
113
+
114
+
computed: {
115
+
userId() {
116
+
return1;
117
+
}
118
+
}
119
+
});
120
+
````
121
+
122
+
98
123
##### Presence channel
99
124
100
125
If you would like to subscribe to presence channel instead, prefix your channel name with`presence:`
@@ -103,7 +128,7 @@ If you would like to subscribe to presence channel instead, prefix your channel
103
128
var vm = new Vue({
104
129
channel: 'presence:user.1.chat',
105
130
echo: {
106
-
'NewMessage': (payload, vm) => {
131
+
'NewMessage': (payload) => {
107
132
console.log('new message from team', payload);
108
133
}
109
134
}
@@ -118,10 +143,10 @@ If there's a scenario where you want to listen to events after certain condition
0 commit comments