Can someone assist me in displaying the contents of an array based on a specific id input? I attempted to use v-model but couldn't figure out a solution.
For instance, when I input 123
, I want to see item1
displayed and when I input 321
, I expect to see item2
.
<template>
<input v-model="inventar[1].id" />
</template>
<script lang="ts">
import { defineComponent, reactive } from 'vue'
interface Inventar {
id: number,
name: string,
size: number
}
export default defineComponent({
name: 'HelloWorld',
setup() {
const selected: number = 123;
const inventar: Array<Inventar> = [];
inventar.push({ id: 123, name: "item1", size: 25 } as Inventar);
inventar.push({ id: 321, name: "item2", size: 20 } as Inventar);
return {inventar,selected}
}
})
</script>
I would greatly appreciate any assistance. Thank you!