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

Can't access component methods when binding :key on a template #2085

Closed
amrnn90 opened this issue Sep 10, 2020 · 3 comments
Closed

Can't access component methods when binding :key on a template #2085

amrnn90 opened this issue Sep 10, 2020 · 3 comments

Comments

@amrnn90
Copy link

amrnn90 commented Sep 10, 2020

Version

3.0.0-rc.10

Reproduction link

https://codesandbox.io/s/happy-fast-vfld6?file=/src/App.vue

Steps to reproduce

Open reproduction link, the code binds :key on a template using a method:

  <template v-for="item in items" :key="itemKey(item)">
    {{item.name}}
  </template>

What is expected?

Should render items normally without throwing an error

What is actually happening?

An error is thrown:

Uncaught ReferenceError: itemKey is not defined

@lanezhao

This comment has been minimized.

@amrnn90
Copy link
Author

amrnn90 commented Sep 10, 2020

@lanezhao
In Vue 3 using key is valid with <template v-for>

@skirtles-code
Copy link
Contributor

skirtles-code commented Sep 10, 2020

It seems the template compiler is generating { key: itemKey(item) } rather than { key: _ctx.itemKey(item) }. That works in function mode but not in module mode.

underfin added a commit to underfin/vue-next that referenced this issue Sep 10, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants