Skip to content

Cannot read property 'emit' of undefined #61

Closed
@gijo-varghese

Description

@gijo-varghese

I've a .vue file like this:

<template>
  <div class="home">
    <h1>Hello</h1>
  </div>
</template>
<script>
export default {
  sockets: {
    connect: () => {
      this.$socket.emit("join_room", "abc");
    },
  }
};
</script>

and I'm getting an error: Uncaught TypeError: Cannot read property 'emit' of undefined

main.js

import VueSocketio from 'vue-socket.io-extended';
import io from 'socket.io-client';
import Vue from 'vue';

import App from './App.vue';

Vue.use(VueSocketio, io('http://localhost:4000'));

new Vue({
  render: h => h(App),
}).$mount('#app');

Metadata

Metadata

Assignees

No one assigned

    Labels

    question 🤔Further information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions