Akryum / Akryum/packt-vue-project-guide
book page 27 code errer
- 主要語言
- JavaScript
- 星號
- 41
- 分支
- 35
- PR 合併指標
- 30 天內沒有已合併 PR
描述
```
NoteBook
{{item.title}}
new Vue({
el: '#notebook',
data(){
return {
content: selectedNote.content,
notes: [],
selectedId:''
}
},
computed: {
// 计算属性,当函数中的数值发生变化,可以返回一个新的值
notePreview(){
return this.selectedNote ? marked(this.selectedNote.content) : '';
// MorkDown转为HTML , marked('## title') --> <h2>title</h2>
},
selectedNote(){
return this.notes.find(item => item.id === this.selectedId);
}
// 上面的item是notes的每一项,然后遍历notes的每一项的id去判断是否 === this.selectedId
// ES5 find()方法,接受一个规则函数,返回一个符合规则的元素,
},
// watch: {
// 侦听改变 当数值发生变化时 返回被监听属性的新值与旧值
// watch以键值对存在 把侦听属性的名字作为key,把侦听选项对象作为value
// 必须有一个handler(newVal, oldVal);
// content: {
// handler(newVal, oldVal){
// console.log('save note:', newVal);
// }
// handler: 'saveNote'
// }
// },
methods: {
// saveNote(newVal){
// // console.log('save note:', newVal);
// localStorage.setItem('content', newVal);
// },
addNote(){
const time = Date.now();//1970到现在的毫秒数 Type is Number
const note = {
id: String(time),
title: 'New note' + (this.notes.length + 1),
content: '**Hi**',
created: time,
favorite: false
}
this.notes.push(note);
// console.log(this.notes);
},
selectNote(item){
this.selectedId = item.id;
console.log(this.selectedId,this.selectedNote);
}
}
})
```
貢獻指南
這個儲存庫沒有索引到貢獻指南
評估
這個 Issue 還沒有評估資料。