首页 > 解决方案 > Set Component props on click

问题描述

I have a button that references to a specific data, then I want to add a component with a props specific to the data that is referenced to that button.

<MyComponent v-bind:props="mydata[0]"/>

that is basically what I'm doing, let say I want to bind a props mydata[1] instead of mydata[2] without typing it manually on the template, I want the props to be dynamic. thanks in advance

标签: javascriptvue.js

解决方案


define a variable called index in data, and change that variable on that button click to the specific index, something like this

<v-btn @click="index = 1">display data of 1</v-btn>

and

<MyComponent v-bind:props="mydata[index]"/>

推荐阅读