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

114
Views
Establecer casilla de verificación seleccionada en Vue

Soy principiante en vue y desarrollo web. Hago mi aplicación con Laravel y Vue.

tengo este codigo:

 created: function () { let self = this; self.setActive('tab1'); axios.get(this.$apiAdress + '/api/tasks/create?token=' + localStorage.getItem("api_token")) .then(function (response) { self.documentDircionary = response.data.documentDircionary; self.selectedDocumentDircionary = response.data.selectedDocumentDircionary; }).catch(function (error) { console.log(error); self.$router.push({path: '/login'}); }); <template v-for="(option) in documentDircionary"> <div class="form-group form-row" :key="option.name"> <CCol sm="12"> <input type="checkbox" name="selectedDocuments[]" :id="option.value" /> {{ option.label }} </CCol> </div> </template>

Este código me muestra entradas, y funciona bien. Tengo un problema con el atributo seleccionado establecido para la casilla de verificación seleccionada.

En la matriz de resultados seleccionadosDocumentDircionary de api:

 "selectedProducts": [1,2,43]

¿Cómo puedo marcar solo esta casilla de verificación, con productos seleccionados?

por favor, ayúdame

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

0

Puede usar el atributo :checked para marcar la casilla de verificación marcada según los productos selectedProducts que tiene.

Demostración de trabajo:

 const app = new Vue({ el: '#app', data() { return { selectedProducts: [1, 2, 43], documentDircionary: [{ name: 'checkbox1', value: 1, label: 'Checkbox 1' }, { name: 'checkbox2', value: 2, label: 'Checkbox 2' }, { name: 'checkbox3', value: 3, label: 'Checkbox 3' }, { name: 'checkbox4', value: 4, label: 'Checkbox 4' }, { name: 'checkbox43', value: 43, label: 'Checkbox 43' }] } } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.0/vue.js"></script> <div id="app"> <template v-for="option in documentDircionary"> <div :key="option.name"> <input type="checkbox" name="selectedDocuments[]" :id="option.value" :checked="selectedProducts.includes(option.value)" /> {{ option.label }} </div> </template> </div>

about 4 years ago · Juan Pablo Isaza Report

0

Puede establecer :checked en función de si la identificación del elemento actual está en la matriz:

 <template v-for="(option) in documentDircionary"> <div class="form-group form-row" :key="option.name"> <CCol sm="12"> <input type="checkbox" name="selectedDocuments[]" :id="option.value" :checked="selectedProducts.includes(option.value)" /> {{ option.label }} </CCol> </div> </template>
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!