Skip to content

Instantly share code, notes, and snippets.

@TheBojda
Created June 10, 2020 10:44
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 TheBojda/13ee0bae2318764f567a2c5ab2d22ad1 to your computer and use it in GitHub Desktop.
Save TheBojda/13ee0bae2318764f567a2c5ab2d22ad1 to your computer and use it in GitHub Desktop.
Simple Vue Native TODO example with NativeBase components
<template>
<nb-container>
<nb-header></nb-header>
<nb-grid>
<nb-row :style="{ height: 60 }" v-for="(todo, idx) in todos" :key="idx">
<nb-col :size="85" :style="{ justifyContent: 'center' }">
<text :style="{marginLeft: 10}">{{todo}}</text>
</nb-col>
<nb-col :size="15" :style="{ justifyContent: 'center' }">
<nb-button iconCenter transparent :on-press="() => removeItem(idx)">
<nb-icon name="trash" />
</nb-button>
</nb-col>
</nb-row>
<nb-row></nb-row>
<nb-row :style="{ height: 60 }">
<nb-col :size="85" :style="{ justifyContent: 'center' }">
<text-input :style="{marginLeft: 10}" placeholder="Todo item" v-model="todoText" />
</nb-col>
<nb-col :size="15" :style="{ justifyContent: 'center' }">
<nb-button iconCenter transparent :on-press="addItem">
<nb-icon name="add" />
</nb-button>
</nb-col>
</nb-row>
</nb-grid>
</nb-container>
</template>
<script>
import Vue from "vue-native-core";
import { VueNativeBase } from "native-base";
Vue.use(VueNativeBase);
export default {
data() {
return {
todoText: "",
todos: []
};
},
methods: {
addItem() {
this.todos.push(this.todoText);
this.todoText = "";
},
removeItem(idx) {
this.todos.splice(idx, 1);
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment