Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<script>
export default {
props: ['value'],
data() {
return {
todo: '',
}
},
mounted () {
console.log(this.value) // Array de todos
},
methods: {
addTodo () {
this.$emit('input', [...this.value, this.todo.trim()])
this.todo = ''
},
removeTodo (todo) {
this.$emit('input', this.value.filter(t => t !== todo))
}
},
render() {
return this.$scopedSlots.default({
todos: this.value,
addTodo: this.addTodo,
removeTodo: this.removeTodo,
inputAttributes: { //datos internos de nuestro componente
value: this.todo,
},
inputEvents: { //eventos de nuestro componente
input: (e) => {
this.todo = e.target.value
},
keydown: (e) => {
if (e.keyCode === 13) {
e.preventDefault()
this.addTodo()
}
}
}
})
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment