Skip to content
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 undefined error #82

Open
acovrig opened this issue Oct 8, 2024 · 2 comments
Open

Vue3 undefined error #82

acovrig opened this issue Oct 8, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@acovrig
Copy link

acovrig commented Oct 8, 2024

Describe the bug
When trying the vue3 example in the Readme:

import { onMounted } from 'vue';

export default defineComponent({
  channels: {
    ChatChannel: {
      connected() {
        console.log('connected');
      },
      rejected() {
        console.log('rejected');
      },
      received(data) {},
      disconnected() {},
    },
  },
  setup() {
    onMounted(() => {
      this.$cable.subscribe({
        channel: "ChatChannel",
      });
    });
  },
});

I get ReferenceError: defineComponent is not defined, so if I change the first line to:
import { onMounted, defineComponent } from 'vue';

I then get Cannot read properties of undefined (reading '$cable') .

I was able to get it to work using this:

<script>
import { defineComponent } from 'vue';

export default defineComponent({
  channels: {
    ChatChannel: {
      connected() {
        console.log('connected');
      },
      rejected() {
        console.log('rejected');
      },
      received(data) { console.log(data); },
      disconnected() { console.log('disconnected'); },
    },
  },
  setup() {},
  mounted() {
    this.$cable.subscribe({
      channel: "ChatChannel",
    });
  },
});
</script>

Am I missing something or should the Readme be updated?

Plugin version (please complete the following information):

versions: {
  "actioncable-vue": "^3.0.4",
  "vue": "^3.4.29"
}
@acovrig acovrig added the bug Something isn't working label Oct 8, 2024
@mclintprojects
Copy link
Owner

@acovrig Thanks for flagging. This is a README issue, and I'll update it shortly.

@joaoVictorDeAndrade
Copy link

Same here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants