Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Vue 3 set ref value inside function

I have value 'reset', that should be set to false when file is uploaded. After fileUpload function is triggered, 'reset' is still 'true' (it is set to 'true' externally), how to set it to 'false' on file upload?

<template>
  reset: {{reset}}<br> // should display variable here
  <div class="fileDnd m0"">
    <label for="fileUploaderInput" class="">
    </label>
    <input
      type="file"
      name="fileUploaderInput"
      @input="fileUpload"
    />
  </div>
</template>

<script>
import { ref, toRefs } from "@vue/reactivity";
export default {
  name: "Upload",
  props: {
    reset: {
      type: Boolean,
      default: false,
    },
  },
  emits: ["upload"],
  setup(props, { emit }) {
    const { reset } = toRefs(props);
    const fileNames = ref("");

    function fileUpload(event) {
      reset.value = false;// should be set here
      const files = event.target.files;

      emit("upload", files);
    }

    return {
      fileNames,
      fileUpload,
      reset,
    };
  },
};
</script>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Since that reset is a prop, it should be updated inside the parent component inside the upload event handler :

uploadHandler(files){
 
//update the reset here
}

or you could create a ref that takes the reset prop as initial value, then update it as you did above

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!