script.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. new Vue({
  2. el: '#app',
  3. data: {
  4. note: {
  5. text: '',
  6. topic: "Домашнее",
  7. color: "white",
  8. important: false
  9. },
  10. notes: []
  11. },
  12. mounted() {
  13. if (localStorage.getItem('notes')) {
  14. try {
  15. this.notes = JSON.parse(localStorage.getItem('notes'));
  16. } catch(e) {
  17. localStorage.removeItem('notes');
  18. }
  19. }
  20. },
  21. computed: {
  22. getNotes() {
  23. return this.notes.slice()
  24. }
  25. },
  26. methods: {
  27. add() {
  28. if (this.note.topic.length == 0 ) this.note.topic = "Домашнее";
  29. if (this.note.color == "yellow") this.note.color = "#f7f7c1";
  30. else if (this.note.color == "blue") this.note.color = "#e3f3ff";
  31. else if (this.note.color == "pink") this.note.color = "#f2d0ea";
  32. else if (this.note.color == "purple") this.note.color = "#d8bfd8";
  33. else if (this.note.color == "green") this.note.color = "#c2ff99";
  34. this.notes.push({ ...this.note });
  35. this.saveData();
  36. this.note.text = '';
  37. this.note.color = "white";
  38. this.note.important = false;
  39. this.note.topic = "Домашнее";
  40. },
  41. remove(index) {
  42. this.notes.splice(index, 1);
  43. this.saveData();
  44. },
  45. saveData() {
  46. const parsed = JSON.stringify(this.notes);
  47. localStorage.setItem('notes', parsed);
  48. }
  49. }
  50. });