Created
August 31, 2017 10:51
-
-
Save Mozartted/53b27c9d3f647a945ce04e530514d5b7 to your computer and use it in GitHub Desktop.
The Axios enhananced
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="col-md-12 contain nopadding"> | |
<note-sidebar v-if="notes" :initialnotes="notes" @noteChosen="noteSelected"></note-sidebar> | |
<note-editor v-if="firstNote" :note="firstNote"/> | |
</div> | |
</template> | |
<script> | |
import NoteEditor from './NoteEditor.vue'; | |
import NoteSidebar from './NoteSidebar'; | |
import axios from 'axios'; | |
import _ from 'lodash'; | |
export default { | |
name: 'note-app', | |
components:{ | |
NoteEditor, | |
NoteSidebar | |
}, | |
computed: { | |
firstNote:{ | |
get:function(){ | |
if(this.currentNote == null){ | |
return _.first(this.notes); | |
} | |
return this.currentNote; | |
}, | |
set: function(value) { | |
this.currentNote = value; | |
} | |
} | |
}, | |
data: function(){ | |
return{ | |
notes:null, | |
currentNote:null | |
}}, | |
methods:{ | |
noteSelected: function(value){ | |
this.firstNote = value; | |
} | |
}, | |
created() { | |
//do something after creating vue instance | |
axios.get('/api/notes').then((res)=>{ | |
console.log(res.data.data) | |
this.notes = res.data.data; | |
}) | |
} | |
} | |
</script> | |
<style lang="scss" scoped> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment