I have a key inside my components data that may be initialised as null or have some strings inside. I want to be able to create as many associatedKeys as I want, while also allowing for it to be initialised as null or with multiple values. The problem I'm having is that each time I am pressing the button to add a new input field, the page is re rendering and the data is then reset once initialised again.
I have been looking at this article, I have placed a debugger inside the addKeys function and am getting the error message this.licence.associatedKeys.$set is not a function. I don't understand this error and am not sure how to add elements to the associatedKeys array
<template>
<div>
<form>
<label>Associated Keys</label>
<button v-on:click="addNewKey">Add new key</button>
<div v-for="(k,index) in licence.associatedKeys" :key="k">
<input type="text" :value="k" @input="licence.associatedKeys[index]=$event.target.value">
</div>
</form>
</div>
</template>
<script>
import util from '~/assets/js/util'
export default {
methods: {
addNewKey() {
this.licence.associatedKeys.$set(this.licence.associatedKeys, null)
}
},
data: () => ({
licence: {
associatedKeys: []
}
})
}
</script>