官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 永城市| 苗栗市| 阿图什市| 观塘区| 唐山市| 新建县| 蛟河市| 介休市| 申扎县| 诸城市| 鞍山市| 南平市| 东乌| 垫江县| 乐平市| 梧州市| 枞阳县| 壶关县| 资源县| 康定县| 莱州市| 桃园县| 莱芜市| 衡南县| 河北省| 中牟县| 江门市| 万载县| 安新县| 龙南县| 如皋市| 奉新县| 师宗县| 云和县| 抚顺市| 奉贤区| 乐平市| 江门市| 阿尔山市| 张家港市| 上饶县|