Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Call form submission programatically upon icon click in Javascript/VueJS

I want my single page application (Vue 3 / Quasar 2) to invoke a logout request to my Spring-based backend.

My first approach was using an axios request when the logout icon has been clicked:

axios.post('http://localhost:8500/logout');

However, this does not work because the AJAX requests run into a CORS issue when following redirects. It seems as if Spring requires this to be a browser-initiated form POST to work correctly.

So I changed my SPA code to this:

<q-form
    action="http://localhost:8500/logout"
    method="post"
    ref="logoutForm"
>
    <q-icon
    name="o_logout"
    size="sm"
    @click="logout"
    />
</q-form>

But I'm struggling with how to call the form's submit event in the logout() method when the icon was clicked.


Update 1

Here is the code snippet:

import { defineComponent, ref } from 'vue';

export default defineComponent({
  name: 'ToolbarElements',
  setup() {
    const logoutForm = ref(null);

    function logout() {
      ref('logoutForm').submit();
    }

    return {logout, logoutForm };
  },
});
</script>

But this gives me the follow error:

vue__WEBPACK_IMPORTED_MODULE_0__.ref(...).submit is not a function


Update 2

I found out that I used the ref in a wrong manner, so I corrected the code to be:

import { defineComponent, ref } from 'vue';

export default defineComponent({
  name: 'ToolbarElements',
  setup() {
    const logoutForm = ref(null);

    function logout() {
      logoutForm.value.submit();
    }

    return {logout, logoutForm };
  },
});
</script>

This results in a new error message:

Uncaught (in promise) TypeError: e is undefined

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!