- 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.
推薦閱讀
- Bootstrap Site Blueprints Volume II
- Mastering Objectoriented Python
- AngularJS Web Application Development Blueprints
- 跟老齊學Python:輕松入門
- CKA/CKAD應試教程:從Docker到Kubernetes完全攻略
- 表哥的Access入門:以Excel視角快速學習數據庫開發(第2版)
- Python深度學習:基于TensorFlow
- Python機器學習算法: 原理、實現與案例
- INSTANT Yii 1.1 Application Development Starter
- Python Data Science Cookbook
- Mastering AWS Security
- Web Developer's Reference Guide
- 零基礎輕松學C++:青少年趣味編程(全彩版)
- 零基礎學Java第2版
- Android編程權威指南(第4版)