Skip to content

Instantly share code, notes, and snippets.

@Mozartted
Created August 31, 2017 11:12
Show Gist options
  • Save Mozartted/ed575357ba05a781ec2ed38e585446ee to your computer and use it in GitHub Desktop.
Save Mozartted/ed575357ba05a781ec2ed38e585446ee to your computer and use it in GitHub Desktop.
New NoteSidebar axios enhanced
<template>
<div class="col-md-3 nopadding">
<div class="note-container">
<div class="note-title">Real Notes</div>
<div class="notes-items" v-for="(note,index) in notes" @click="selectNotes(note)">
<h5 class="font-fa">{{note.title}}</h5>
<span @click="remove(note,index)">click to remove</span>
</div>
<div class="add-note" @click="createNote">New Note?</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
export default{
props:['initialnotes'],
data: function(){
return {
notes:this.initialnotes
}
},
methods:{
selectNotes:function(note){
this.$emit('noteChosen',note);
},
remove: function(note,index){
axios.delete('/api/notes/delete/'+note.id).then((res)=>{
console.log(res.data);
this.notes.splice(index,1);
})
},
createNote:function(){
axios.post('/api/notes/create',{
title:'What\' on your mind',
content:'Say something Nice'
}).then((res)=>{
this.notes.push({
title:'What\' on your mind',
content:'Say something Nice'
});
})
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment