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

117
Views
Cómo hacer Vue de "enlace bidireccional"

Tengo un componente secundario cuya función es cargar una foto. Foto cargada asignada a los datos del componente secundario denominado "foto". Necesito vincular datos principales llamados "archivo" con datos secundarios llamados "foto". Y cuando se cambia la "foto", el "archivo" también debe cambiarse.

Componente hijo:

 <template> <div class="select"> <img v-if="previewFile" :src="previewFile" alt="" /> <img v-else src="/images/empty.jpg" alt="" /> <label class="btn" for="image-upload">{{ btnLabel }}</label> <input id="image-upload" type="file" ref="file" @change="uploadFile" /> </div> </template> import { mapGetters } from "vuex"; export default { name: "SelectPhoto", data() { return { file: null, previewFile: null, }; }, methods: { uploadFile() { this.file = this.$refs.file.files[0]; } } }

Componente principal:

 <template> <SelectPhoto :btn-label="text.RU.photoSelect.choosePhoto" v-model:file.sync="file"/> <BaseButton :label="text.RU.photoSelect.knowName" @do="$emit('getResult', file, previewFile)" /> </template> <script> export default { data() { return { file: null, }; }, }; </script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ya usó $emit en su componente BaseButton . También podría usarlo para this.file . En su componente hijo como este:

 uploadFile() { this.file = this.$refs.file.files[0]; this.$emit('sendMyFile', this.file) }

En su componente principal, para reaccionar a la acción:

 <SelectPhoto @sendMyFile="getMyFile" :btn-label="text.RU.photoSelect.choosePhoto" v-model:file.sync="file"/>

También en el componente principal, haga lo que quiera con the.file :

 methods: { getMyFile(file) { // do something } }
about 4 years ago · Juan Pablo Isaza 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!