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

throw error when use Object.freeze() to return value in setup #233

Closed
houfeng0923 opened this issue Jan 20, 2020 · 2 comments · Fixed by #366
Closed

throw error when use Object.freeze() to return value in setup #233

houfeng0923 opened this issue Jan 20, 2020 · 2 comments · Fixed by #366
Labels
bug Something isn't working has PR

Comments

@houfeng0923
Copy link

this case is in vue2.x , and throw error below:

Property or method "city" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

code like this:

<template>
{{city.name}}
</template>
<script>
import { createComponent } from '@vue/composition-api';
export default createComponent({
  setup() {
    const city = Object.freeze({name: 'dl'});
    return {city};
  }
});
</script>

so, why setup() not allow return freeze property ? and how to use freeze object in hook api ?

thank u

@RANGELJ
Copy link

RANGELJ commented Feb 8, 2020

I am not sure the use case, my guess is that your object named "city" is not reactive state because you want it to be a constant, and because it is not reactive state, it cannot be used in a template, if you are trying to use it as a constant, it is better to use directly in the template:
<template> dl </template>

@houfeng0923
Copy link
Author

in vue2.x, we can make model frozen for performance ;
like demo

but , in setup way, why not ?

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

Successfully merging a pull request may close this issue.

4 participants