Using async/await in combination with Vuex and Feathers

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
  },
}

Answer №1

Ensure to include a return statement right before the uploadService.create line for proper functionality.

index.js

export const initiateUpload = ({commit}, reader) => {
  return uploadService
    .create({uri: reader.result})
    ...
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determine if a draggable item is currently positioned over another element

In my body, there are several divs located: <div id="one"></div> <div id="two"></div> <div id="three"></div> All of these divs are draggable using jqueryUI: var $divs = $('#one, #two, #three'); $divs.draggab ...

transferring information from the Quill text editor to the Node.js server

Is there a way to send data from Quilljs on the frontend to node.js on the backend? I've been searching for examples, but haven't found anything related to the backend. I tried reading the documentation for Quilljs, but I'm still struggling ...

Dividing CSV Data into Two File Outputs

I've got a CSV file that's structured like this: Docushare Host locale, created_at, version en,Wed Feb 21 17:25:36 UTC 2018,07.00.00.C1.609 User handle, client_data, docCountQuota User-12,,-2 Document handle,client_data,cfSpecialWords Document ...

I encountered an issue with Storyshot while using Storybook/Vue, where I received an error message stating "Module not found: Error: Can't resolve 'fs'"

For more detailed information, please refer to this ticket. Here is a summary of the current situation: Explanation of the Issue A significant 'fs' resolution issue occurred with the storyshot configuration after Jest had been configured and St ...

Nuxt and Express server are unable to receive API requests when in production mode and the /dist directory

My Nuxt app is running smoothly on my local server, with all API requests working perfectly using the serverMiddleware property in nuxt.config.js. However, when I run yarn generate, the path to the API server gets lost and no data is loaded. Here are some ...

Retrieving the 'red' pixel data from the texture rendered with gl.texImage2D

My objective is to transfer a Float32array to my fragment shader using a texture in order to process the data within the shader and then send it back to JavaScript. Since the data is not in the form of an image, I opted to transmit it as 'gl.R32F&apos ...

Toggle between classes by clicking on the next or back button

Looking to create a multi-step form where the initial step is visible while the rest are hidden using the "hide" class. I want to toggle visibility of each step with Next and Back buttons, displaying only one step at a time. Can someone assist with this? ...

Setting session expiration for an HTML page in MVC with JavaScript - A step-by-step guide

I'm working on a HTML page within an MVC framework that includes a button click function. I'm trying to figure out how to redirect the user to the login page if the page remains idle for 30 minutes. I've attempted using the code snippet belo ...

Displaying JSON data in a browser using Node.js without the need for refreshing the page

I am currently working on a node.js server that fetches JSON data from an external source and displays it in a browser window. I need assistance in setting up an automatic update every minute to reflect any changes in the JSON without requiring a manual re ...

Creating a prompt within a while loop

Issue with the code is that it should only progress if the user inputs "rock", "paper" or "scissors". However, after re-entering any input the second time, it still moves on despite passing the condition in the while loop. For instance, entering "asdf" p ...

In Internet Explorer 11, React 15.4.1 does not support using objects as valid child components

When trying to render a collection of children in React, make sure to use an array instead of objects. If you encounter the error "Objects are not valid as a React child," consider wrapping the object using createFragment(object) from the React add-ons. Do ...

Is there a way to set the default state of a checkbox in a spring-form?

I have set up my web content using spring-boot with .jsp files. The controller code is as follows: @Slf4j @Controller @AllArgsConstructor @SessionAttributes({"language", "amount", "words"}) public class LanguageController { private LanguageService lang ...

Is there a way to retrieve the information from the v-text-field without using the v-model directive?

<div v-for="i in parseInt(questionCount)" :key="i"> <v-layout> <v-flex xs6 offset-3 mt-15" > <label for=""> Enter question number {{index}}:</label> <v-text-fi ...

Even with React.memo(), functional components continue to trigger re-renders

I am facing an issue with my button component that contains a button inside it. The button has a state isActive and a click function passed to it. Upon clicking the button, the isActive flag changes, triggering the app to fetch data accordingly. However, t ...

How can I retrieve and manipulate the text within an option tag of a form using JavaScript?

<select name="products"> <option value=""> - Choose - </option> <option value="01">table</option> <option value="02">chair</option> <option value="03">book</option> <option value= ...

Attach actions to specialized component

Working with Vue3 I'm currently in the process of developing a custom component and I want to bind events to the input element within it. How can I achieve this now that $listeners are no longer available? I am unable to use v-bind="$attrs" ...

What are the steps to create a dynamic website using vuetify?

I am interested in creating an adaptive website using Vuetify: https://vuetifyjs.com/en/ This means there will be multiple versions of the website catered to different devices. An adaptive design will offer various designs for different screen sizes, inc ...

Is React the ideal choice for implementing a shared state subscription mechanism in your project?

Trying to determine if this falls under the "pub/sub" pattern or a variation of it. The goal is to establish a shared state where different components can subscribe to it and only receive updates when the state changes. const useForceUpdate = () => useR ...

Having difficulty uploading a file using a formGroup

Currently, I am using Angular to create a registration form that includes information such as name, email, password, and avatar. For the backend, I am utilizing NodeJS and MongoDB to store this information. I have successfully written the registration API ...

How can you show a top-level component across various routed pages in Nuxt without having to reload it each time?

Recently starting a new job, I have been tasked with creating a website using nuxt. In a typical nuxt layout file, the structure would look something like this: <NavMenu /> <Nuxt /> - various routed pages <Footer /> When transitioning be ...