Last active
March 29, 2020 20:48
-
-
Save jfbrennan/1765ae2236a50e08602cc99f894b9165 to your computer and use it in GitHub Desktop.
Vue Single File Component with all the basics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<p>Todo count: {{todos.length}}</p> | |
<input ref="newTodo" type="text"> | |
<button v-on:click="add">Add</button> | |
<ul v-if="todos.length"> | |
<li v-for="(todo, i) of todos" :key="i">{{todo}} <button v-on:click="remove(i)">Remove</button></li> | |
</ul> | |
</template> | |
<script> | |
export default { | |
name: 'my-todos', | |
// Lifecycle methods: https://vuejs.org/v2/api/#Options-Lifecycle-Hooks | |
data () { | |
return { | |
todos: [] | |
} | |
}, | |
methods: { | |
add(e) { | |
const todo = this.$refs.newTodo.value; | |
this.todos.push(todo); | |
}, | |
remove(i) { | |
this.todos.splice(i, 1); | |
} | |
} | |
} | |
</script> | |
<style scoped> | |
ul { list-style: none } | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment