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

219
Views
Iteración con v-for usando una función que devuelve una matriz en vueJs

Tengo un componente principal que llama a un componente secundario, vea el componente secundario a continuación y el componente principal le pasa una serie de autores

Matriz entrante con componente principal

 [ { "name":"James T. Kirk", "series":[ { "title":"myserie1", "kind":"comedy" } ] }, { "name":"Spock", "series":[ { "title":"Star Trek" "kind":"action" }, { "title":"The Next Generation" "kind":"comedy" } ] }, { "name":"Jean-Luc Picard", "series":[ ] }, { "name":"Worf", "series":[ ] } ]

componente hijo

 <template> <div v-for="(auth,i) in allAuthors" :key="auth.id" class="d-sm-flex mt-8 align-start"> // here i call my allAuthors method <div> <div class=""> <p>{{auth.name }}</p> <p>{{auth.series[i].title}}</p> </div> <div class="py-4">{{auth.series[i].kind}}</div> </div> </div> </template> <script> export default { name: "MyListItem", props: { users: [] }, data () { return { author:[] } }, created: function() { this.author = this.allAuthors console.log(this.author); }, computed:{ }, methods: { allAuthors() { let newArr = this.users.find(x => x.series.length === 0) return newArr } } } </script>

Quiero iterar en el componente secundario en la tabla que proviene del componente principal filtrando la tabla del componente principal en un método y llamando a este método en v-for . Quiero filtrar las matrices para tener solo una matriz cuya serie exista (diferente de vacía), es decir, cuya propiedad de serie contenga al menos un elemento. Luego use esta matriz en v-for . problema no funciona.

como puedo hacerlo por favor

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

0

Puede crear una propiedad computed :

 Vue.component('MyListItem', { template: ` <div> <div v-for="(auth, idx) in allAuthors" :key="idx" class="d-sm-flex mt-8 align-start"> <div class=""> <p>{{auth.name }}</p> <ul> <li v-for="(serie, i) in auth.series" :key="i"> <p>{{ serie.title }}</p> <div class="py-4">{{ serie.kind }}</div> </li> </ul> </div> </div> </div>`, props: { users: {type: Array} }, computed: { allAuthors() { return this.users.filter(x => x.series?.length > 0) } } }) new Vue({ el: '#demo', data() { return { items: [ {"name":"James T. Kirk", "series":[{"title":"myserie1", "kind":"comedy"}]}, {"name":"Spock", "series":[{"title":"Star Trek", "kind":"action"}, {"title":"The Next Generation", "kind":"comedy"}]}, {"name":"Jean-Luc Picard"}, {"name":"Worf", "series":[]} ] } } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="demo"> <my-list-item :users="items" /> </div>

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!