Skip to content

Instantly share code, notes, and snippets.

@Mozartted
Created August 31, 2017 10:51
Show Gist options
  • Save Mozartted/53b27c9d3f647a945ce04e530514d5b7 to your computer and use it in GitHub Desktop.
Save Mozartted/53b27c9d3f647a945ce04e530514d5b7 to your computer and use it in GitHub Desktop.
The Axios enhananced
<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