Skip to content

Instantly share code, notes, and snippets.

@MicroDreamIT
Created September 27, 2018 08:31
Show Gist options
  • Save MicroDreamIT/75f570f478f9e6d64e5f4ff3d15a9c19 to your computer and use it in GitHub Desktop.
Save MicroDreamIT/75f570f478f9e6d64e5f4ff3d15a9c19 to your computer and use it in GitHub Desktop.
todo for dynamic object and key
<template>
<div>
<input type="text" v-model="addValue" ref="addValueRef" @keyup.enter="addToObject()">
<button @click.prevent="addToObject()">add {{pivotal}}</button>
<div v-for="(value, index) in obj[pivotal]">
{{index + 1 }}. <input type="text" v-model="obj[pivotal][index]" :disabled="true" :ref="'input' + index">
<i
@click.prevent="delFromObject(index)"
class="mdi mdi-delete trash-can-outline"
></i>
<i
class="mdi mdi-pen"
@click.prevent="allowEdit(index)"
></i>
</div>
</div>
</template>
<script>
export default {
props:['obj', 'pivotal'],
data(){
return {
addValue:''
}
},
methods:{
allowEdit(index){
this.$refs['input'+index][0].removeAttribute('disabled')
this.$refs['input'+index][0].focus()
},
addToObject(){
if(!this.addValue) return null
this.obj[this.pivotal].push(this.addValue)
this.addValue=''
this.$refs.addValueRef.focus()
},
delFromObject(index){
this.obj[this.pivotal].splice(index, 1)
}
}
}
</script>
<style scoped>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment