Skip to content

Instantly share code, notes, and snippets.

@neves
Created March 18, 2017 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neves/2ccaf875339fa658f5f4ecd218985115 to your computer and use it in GitHub Desktop.
Save neves/2ccaf875339fa658f5f4ecd218985115 to your computer and use it in GitHub Desktop.
<template lang="html">
<input class="v-tag-input" type="text" v-model="editableValue">
</template>
<script>
export default {
name: 'v-tag-input',
props: {
value: {
type: Array,
default: () => [] // factory function
},
separator: {
type: String,
default: ' '
}
},
computed: {
editableValue: {
get () {
return (this.value || []).join(this.separator)
},
set (newValue) {
newValue = newValue.trim() ? newValue.split(this.separator) : []
this.$emit('input', newValue)
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment