I'm simply trying to use $refs in my Vue 3 app but I keep getting the Typescript error Object is of type 'unknown'. I'm not sure how to fix this.
Here's my .vue file:
<template>
<div id="content">
<h2>
Add Products
</h2>
<Multiselect v-model="products"
mode="tags"
placeholder="Select one or more products..."
ref="multi"
:searchable="true"
:createTag="true"
:options="options"></Multiselect>
<div v-for="(product, index) in this.products"
v-bind:key="index"
v-bind:name="product">
<Button class="primary"
text="Remove"
@click="removeProduct(product)"></Button>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import Button from '@/components/Button.vue'
import Multiselect from '@vueform/multiselect'
export default defineComponent({
name: 'TrackSymptoms',
components: {
Button,
Multiselect
},
data () {
return {
products: [],
options: [
{ value: 'Alpha', label: 'Alpha' },
{ value: 'Bravo', label: 'Bravo' },
{ value: 'Charlie', label: 'Charlie' },
{ value: 'Delta', label: 'Delta' }
]
}
},
methods: {
removeProduct (product: string) {
this.$refs.multi.deselect(product)
}
}
})
</script>
The line this.$refs.multi.deselect(product) in the removeProduct function is the one producing the error.
This is how it's instructed to be used via the docs:
mounted() {
this.$refs.multiselect.open()
}