Please review my code below. I am attempting to integrate Async Await into vuex. While everything is functioning properly, I would like to call another action after this one using async await. However, the expected result is not being achieved as the console is showing console.log("after all this" +res) with the res variable being undefined.
action.js
import { createUpload } from '../api/index'
export default {
fetchImageUrl: async({ commit }, reader) => {
let res = await createUpload({ commit }, reader);
console.log("after all this" +res)
}
}
api/index.js
import { feathersClient } from './apiClient'
const uploadService = feathersClient.service('uploads');
export const createUpload = ({commit}, reader) => {
uploadService
.create({uri: reader.result})
.then(function(response){
commit('setImageUrl', { url: response.imageurl })
return true;
});
}
mutations.js
export default {
setImageUrl: (state,{ url } ) => {
state.imageUrl = url
}
}
LeftPanel.vue
const reader = new FileReader();
export default {
name: 'left-panel',
data () {
return {
open: true
}
},
methods: {
uploadFile: function (event) {
let store = this.$store;
let file = event.target.files[0];
reader.readAsDataURL(file);
reader.onload = function(event) {
return store.dispatch('fetchImageUrl',reader)
};
}
},
components: {
'add-text': AddText
},
}