Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Vue Single File Component with all the basics
<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>
export default {
name: 'my-todos',
// Lifecycle methods:
data () {
return {
todos: []
methods: {
add(e) {
const todo = this.$refs.newTodo.value;
remove(i) {
this.todos.splice(i, 1);
<style scoped>
ul { list-style: none }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment