O
O
overus2019-12-20 12:52:16
Vue.js
overus, 2019-12-20 12:52:16

How to pass a parameter from v-for to v-for one level down?

Hello!
There is code that has two v-for loops . I need to get the target
key , which is in the items hash. To do this, I pass item from items as a parameter to the " child " v-for, but I get undef. How to correctly pass the item, in which the key is target, to the " child " v-for? jsfiddle

<div id="app">
  <div 
    v-for="item in items">
    {{item.target}}
     <p
       v-for="(data, item) in item.text"
       @click="getData(item)"><!-- (data, item) - тут из item хочу получить ключ target, который получаем из v-for="item in items" -->
       {{data.desc}}
     </p>
  </div>  
</div>

new Vue({
  el: "#app",
  data: {
    items: [
      { 
      	target: "One",
      	text: [{
        	title: "First title",
          desc: "First desc",
        }],
       },
      { 
      	target: "Two",
      	text: [{
        	title: "Second title",
          desc: "Second desc",
        }],
      },
    ]
  },
  methods: {
  	getData(item) {
    	console.log(item.target);
    }
  }
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2019-12-20
@overus

(data, item)replaced bydata

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question