Home > Net >  How can i get the selected item - Vue2
How can i get the selected item - Vue2

Time:01-15

i have one method to show an list itens, but i need to get the select item and show in a template, how could i do it

method:

fieldsForm() {
  return [
    {
      name: "codigoConta",
      data: setOpcaoDefault(getLista().contas),
      label: "Teste",
      type: "list",
      size: 6,
      value: getLista().contas,
      required: true,
    },

and i need to put the selected item here:

Posição do saldo em {{need to put here- the selected item }}{{ new Date().toLocaleDateString() }} - {{ new Date().toLocaleTimeString() }}

image

CodePudding user response:

You will need a method to return the selected item (e.g. selectedItem()). You then can insert the selected item by calling the method in the place you want.

Posição do saldo em {{ selectedItem() }}{{ new Date().toLocaleDateString() }} - {{ new Date().toLocaleTimeString() }}

CodePudding user response:

Here how you can do this. I will describe you with an example

Define two variables name selectedItemIndex and selectedItem

@click on item call a method itemSelect(index)

<div v-for="(item,index) in list"><div @clikc="itemSelect(index)">{{item}}</div></div>


itemSelect(index){
this.selectedItemIndex=index;//selected item index to change background color of  selected item
this.selectedItem=this.list[index];//it is your list
}
  •  Tags:  
  • Related