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

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.

主站蜘蛛池模板: 成武县| 长顺县| 改则县| 永州市| 泽库县| 二连浩特市| 弥渡县| 西盟| 唐海县| 晋州市| 崇文区| 和顺县| 石楼县| 谢通门县| 鄂伦春自治旗| 福州市| 阿拉善左旗| 建昌县| 屏山县| 淮北市| 高州市| 图木舒克市| 汝阳县| 电白县| 揭西县| 绥中县| 新乡市| 文山县| 璧山县| 利辛县| 蚌埠市| 潢川县| 平江县| 铜梁县| 长兴县| 昌图县| 正定县| 蒙自县| 马龙县| 昌宁县| 海兴县|