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

References to access methods in a v-for fail (vue 2) #8

Closed
YerlinMatu opened this issue Mar 3, 2022 · 1 comment
Closed

References to access methods in a v-for fail (vue 2) #8

YerlinMatu opened this issue Mar 3, 2022 · 1 comment

Comments

@YerlinMatu
Copy link

YerlinMatu commented Mar 3, 2022

 <v-col
    cols="12"
    v-for="(signature, index) in formData.signatures"
    :key="index"
  >
        <VPerfectSignature
          width="100%"
          height="300px"
          :stroke-options="strokeOptions"
          :ref="`signatures${index}`"
        />
       <v-btn  @click="$refs[`signatures${index}`].clear()">Clear</v-btn>
 </v-col>

ERROR:

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler: "TypeError: _vm.$refs[("signatures" + index)].clear is not a function"

vue.runtime.esm.js?2b0e:1897 TypeError: _vm.$refs[("signatures" + index)].clear is not a function

@wobsoriano
Copy link
Owner

wobsoriano commented Mar 3, 2022

https://v2.vuejs.org/v2/api/#ref

It wasn't able to find the appropriate element. To fix this, update your button click like this

<v-btn @click="clearSignature(`signatures${index}`)">
clearSignature(index: string) {
  if (this.$refs[index]) {
    this.$refs[index].clear()
  }
}

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