- Vue.js 2 Web Development Projects
- Guillaume Chau
- 228字
- 2021-07-02 22:34:27
A method to create a new note
Each of our notes will be an object with the following data:
- id: This will be the note unique identifier
- title: This ;will contain the name of the note displayed in the list
- content: This ;will be the note markdown content
- created: This ;will be the date the note was created
- favorite: This ;will be a Boolean that allows for marking a note that will be displayed at the top of the list as favorite
Let's add a method that will create a new note and call it addNote, which will create a new note object with a default value:
methods:{ // Add a note with some default content and select it addNote () { const time = Date.now() // Default new note const note = { id: String(time), title: 'New note ' + (this.notes.length + 1), content: '**Hi!** This notebook is using [markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) for formatting!', created: time, favorite: false, } // Add to the list this.notes.push(note) }, }
We take the current time (which means the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC), which will be a perfect way to have a unique identifier on each note. We also set default values, such as a title and some content, plus the created date and the favorite ;Boolean. Finally, we add the note to the notes array property.
推薦閱讀
- Boost C++ Application Development Cookbook(Second Edition)
- Python Network Programming Cookbook(Second Edition)
- Python高效開發(fā)實(shí)戰(zhàn):Django、Tornado、Flask、Twisted(第3版)
- RISC-V體系結(jié)構(gòu)編程與實(shí)踐(第2版)
- Java Web開發(fā)詳解
- App Inventor創(chuàng)意趣味編程進(jìn)階
- 編寫高質(zhì)量代碼:改善Objective-C程序的61個(gè)建議
- Learning Node.js for .NET Developers
- 人工智能算法(卷1):基礎(chǔ)算法
- R Data Science Essentials
- Mastering OAuth 2.0
- Java Hibernate Cookbook
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)案例教程(第二版)
- Offer來了:Java面試核心知識(shí)點(diǎn)精講(框架篇)
- 軟技能2:軟件開發(fā)者職業(yè)生涯指南