Skip to content

Update state in a event listener #1788

Discussion options

You must be logged in to vote

I found a few issues in your code:

  • If you use this inside a callback, you need to use the arrow function to preserve the context:
    rec.onresult = (e) => {
      //...
      this.voiceKeyWord = keyWord;
    };
  • Don't mix Composition and Options API in one single file. Your App.vue can be simplified to
    export default {
      setup() {
        const voiceStore = VoiceRecognitionStore();
    
        return { voiceStore };
      },
    };

I would also recommend you to update your vue dependencies (e.g vue 2.7), there seem to be a few bugs related to the outdated version

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ChahinDB7
Comment options

@ChahinDB7
Comment options

@posva
Comment options

posva Nov 9, 2022
Maintainer

@ChahinDB7
Comment options

Answer selected by ChahinDB7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1786 on November 09, 2022 07:52.