Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- import { todosCollection } from './firebase';
- export default {
- name: 'app',
- data () {
- return {
- newTodo: '',
- todos: []
- }
- },
- firestore() {
- return {
- todos: todosCollection.orderBy('createdAt', 'desc')
- }
- },
- methods: {
- addTodo() {
- todosCollection.add({
- text: this.newTodo,
- completed: false,
- id: this.todos.length,
- createdAt: new Date()
- })
- .then(function(docRef) {
- console.log("Document written with ID: ", docRef.id);
- })
- .catch(function(error) {
- console.error("Error adding document: ", error);
- });
- this.newTodo = '';
- }
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement