-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vue3 setup how to define channels? #66
Comments
same questions |
This is not an ideal solution, but I hope this may works. It looks like actioncable-vue doesn't register channel in composition API, so you have to do it manually. // app.vue
<script>
import { defineComponent, getCurrentInstance, onMounted } from 'vue';
export default defineComponent({
setup() {
const instance = getCurrentInstance();
const cable = instance.proxy.$cable;
const myChannelHandlers = {
connected: () => console.log('channel connected'),
rejected: () => console.log('channel rejected'),
received: (data) => console.log('channel received', data),
disconnected: () => console.log('channel disconnected'),
};
const subscribeChannel = (channelName, channelHandlers) => {
cable.subscribe({ channel: channelName });
cable._addChannel(channelName, channelHandlers, {
_uid: instance.uid,
_value: instance.proxy,
});
};
onMounted(() => subscribeChannel('MyChannel', myChannelHandlers));
}
})
</script> |
Merged
@Davidzhu001 @Winters0727 @Sylor-huang This is fixed in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, guys
I use vue
3.2.25
and rails7.0
.I had successed subscribe channel, but it can't
console.log
when it's connected. I usedvue3 setup
.In browser console, I can not get
console.log('connected')
and also can not consolereceived()
log. I think maybe I used setup in vue, sochannels
can not usedefineComponent
?If it is , how to define
channels
in vue setup? Thanks so much~The text was updated successfully, but these errors were encountered: