Vue composition API calling child component method
Asked Answered
K

1

6

TLDR; In v2, this.$refs does the job but how can I do that in v3 composition api?

I am trying to use CustomUpload feature of PrimeVue in Vue3, but that API does not clear the upload files after uploading them and I need to call clear() method of the child component in the parent component to clear the files and refresh the button.

Here's my App.vue

<template>
  <FileUpload
    name="upload"
    url="/"
    mode="basic"
    :auto="true"
    :maxFileSize="26214400"
    :fileLimit="1"
    :customUpload="true"
    @uploader="upload"
  />
  <Button name="lalaal">qweeq</Button>
</template>

<script>
import FileUpload from 'primevue/fileupload'

export default {
  setup() {
    const upload = e => {
      console.log('testing', e)
    }
    return { upload }
  },
  components: {
    FileUpload
  }
}
</script>

Thanks

Kenway answered 27/10, 2020 at 9:8 Comment(0)
V
4

You could use template ref then use uploadFile.value instead of this.$refs.uploadFile :

<template>
  <FileUpload
    ref="uploadFile"
    name="upload"
    url="/"
    mode="basic"
    :auto="true"
    :maxFileSize="26214400"
    :fileLimit="1"
    :customUpload="true"
    @uploader="upload"
  />
  <Button name="lalaal">qweeq</Button>
</template>

<script>
import FileUpload from 'primevue/fileupload'
import {ref} from "vue";

export default {
  setup() {
    const uploadFile=ref(null)
 
    
    const upload = e => {
      console.log('testing', e)
    }
    return { upload,uploadFile}
  },
  components: {
    FileUpload
  }
}
</script>
Vizier answered 27/10, 2020 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.