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

for statement in inline handler #7238

Closed
JetLua opened this issue Nov 29, 2022 · 0 comments · Fixed by #7245
Closed

for statement in inline handler #7238

JetLua opened this issue Nov 29, 2022 · 0 comments · Fixed by #7245

Comments

@JetLua
Copy link

JetLua commented Nov 29, 2022

<script setup>
import { reactive } from 'vue'

const state = reactive({
  list: [1, 2, 3]
})

const {log} = console
</script>

<template>
  <h1>{{ msg }}</h1>
  <button @click="() => {
         for (const x of state.list) {
                  log(x) // output: undefined
        }         
  }">Click</button>
</template>

workaround:

  <button @click="() => {
         let x
         for (x of state.list) {
                  log(x) //output: 1, 2, 3
        }         
  }">Click</button>

SFC Playground

Originally posted by @JetLua in #7237

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

Successfully merging a pull request may close this issue.

2 participants