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

variable scope inside onchange callback #72

Open
asifu5057 opened this issue Jan 14, 2021 · 3 comments
Open

variable scope inside onchange callback #72

asifu5057 opened this issue Jan 14, 2021 · 3 comments

Comments

@asifu5057
Copy link

asifu5057 commented Jan 14, 2021

Hi, I have the following code, onChange callback get call correctly and working but the problem is that this.saveData() method is not working because this is out of scope? how I will access other variables using this inside onChange callback?

Please help me or please tell me some other workaround?

<template>
	<editor ref="editor" :config="config" :initialized="onInitialized"/>
</template>

<script>
	config: {
	  onReady: () => {
             console.log('on ready')
          },
          onChange: (args) => {
             console.log('Now I know that Editor\'s content changed!', args)
             **this.saveData(args);**
          },
	}
</script>
@ChangJoo-Park
Copy link
Owner

Hello @asifu5057, I think you should use function not arrow function. If it is not working, please give me an example with codesandbox etc.

@asifu5057
Copy link
Author

Thanks @ChangJoo-Park for the quick response.

I tried function but its not working, I want to access this variables in onChange callback but it shows error Cannot read property 'saveData' of undefined. here is the link to codesandbox . Please check if you have any other question just let me know.
https://codesandbox.io/s/falling-sunset-g9cku?file=/src/components/HelloWorld.vue

@asifu5057
Copy link
Author

Hello @ChangJoo-Park I have already given you an example and sent you a link of codesandbox, could you please help me out in this that why is this happening and how to resolve this issue if I want to access other variables inside callback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants