Akryum / Akryum/packt-vue-project-guide
book page 27 code errer
- Linguagem predominante
- JavaScript
- Estrelas
- 41
- Forks
- 35
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
```
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);
}
}
})
```
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Avaliação
Esta issue ainda não foi avaliada.