Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. <script>
  2. import { todosCollection } from './firebase';
  3.  
  4. export default {
  5. name: 'app',
  6. data () {
  7. return {
  8. newTodo: '',
  9. todos: []
  10. }
  11. },
  12. firestore() {
  13. return {
  14. todos: todosCollection.orderBy('createdAt', 'desc')
  15. }
  16. },
  17. methods: {
  18. addTodo() {
  19. todosCollection.add({
  20. text: this.newTodo,
  21. completed: false,
  22. id: this.todos.length,
  23. createdAt: new Date()
  24. })
  25. .then(function(docRef) {
  26. console.log("Document written with ID: ", docRef.id);
  27. })
  28. .catch(function(error) {
  29. console.error("Error adding document: ", error);
  30. });
  31. this.newTodo = '';
  32. }
  33. }
  34. }
  35. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement