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

459
Views
¿Adjuntar datos dinámicos a vue js v-for sin volver a procesar la lista completa?

tengo la siguiente plantilla en vue 2 (versión simplificada):

 <template> <div> <div v-for="(data, index) in allData" :key="index"> <app-collection :data="data" :index="index"></app-collection> </div> </div> </template>

Mis datos son los siguientes:

 data: function(){ return { allData: [] } }

Luego tengo un botón de cargar más cuando hago clic en Llamo a un método que obtiene datos de una API y luego los agrega a allData en un bucle forEach como este:

 this.allNFT.push({name: "name 1", age: 25"})

Mi problema es que cada vez que agrego datos nuevos, se vuelve a representar la lista completa en lugar de solo agregarla al final.

¿Hay alguna manera de evitar eso y simplemente agregar nuevos datos?

Aquí hay una descripción general más global de mi código en una versión simplificada (todavía no tengo la API en línea):

 <template> <div> <div id="collectionList" class="form-group" v-else> <div class="row"> <div class="col-lg-4" v-for="(data, index) in allData" :key="data.assetId+'_'+index"> <app-collection :data="data" :index="index"></app-collection> </div> </div> <button class="btn btn-primary" v-if="loadMore" @click="getallData()">Load more</button> <div v-else class="text-center">{{ allData.length ? 'All data loaded' : 'No data found' }}</div> </div> </div> </template> <script> import collection from '@/components/content/collection/collection.vue' export default { data: function(){ return { loadMore: true, allData: [], perpage: 25, currentPage: 1 } }, components: { 'app-collection': collection }, created: function(){ this.init() }, methods: { init: async function(){ await this.getallData() }, getallData: async function(){ let filtered = { "page": this.currentPage, "perpage": this.perpage, } try{ let getData = await fetch( "http://localhost:3200/secondary/paginate-filter", { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify( filtered ) } ) getData = await getData.json() if(getData.length){ getData.forEach((elm) => { this.allData.push({name: elm.name, age: elm.age}) }) } this.currentPage++ if(getData.length < this.perpage){ this.loadMore = false } }catch(e){ console.log(e) } }, } }; </script>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si de api recibe solo la siguiente página, puede usar

 this.allData.push(...getData); //If you want to change response data this.allData.push(...getData.map(d => ({name: d.name, age: d.age})))

Si su servidor regresa con datos de la página anterior, debe reasignar datos

 this.allData = getData.map(d => ({name: d.name, age: d.age}))
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!