Double submission issue plagues Vue component

My data model involves a Site with coordinates that can be linked to an Observation. When a user submits both a Site and Observations, they are stored in IndexedDB using localForage. The Outbox component handles posting these to the server when the user is online.

The issue I'm facing is that while Sites are posted correctly, Observations are being posted twice. I lack experience with async/await and try/catch. Below is the code for the submit button:

<b-button
      v-if="this.obsOutbox.length"
      @click.once="syncDb"
      variant="dark"
      size="lg"
      class="m-5 w-75"
    >
      <b-spinner small v-if="syncing"></b-spinner>&nbsp;&nbsp;Upload data
    </b-button>

And here is the script snippet for the component:

<script>
import api from '@/api.js'
import GlobalComponents from '@/globalComponents.js'
import { contextMixin } from '@/mixins/context.js'
import localForageMixin from '@/mixins/localForageMixin.js'
import onlineMixin from '@/mixins/onlineMixin.js'

export default {
  title: 'Outbox',
  name: 'Outbox',
  // Other script contents omitted for brevity...
}
</script>

Answer №1

Try removing the .once from the @click event listener and then test it.

If that doesn't resolve the issue, inspect the loop section within the syncDb function. It's possible that it's running twice.

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

Issue with Laravel: Validation unique during update process consistently not working

Recently, I encountered a puzzling issue with my update form which includes an image and other data that needs to be updated. I decided to change the default route key from ID to name, and also set up a separate form request for validating requests. Everyt ...

Leverage the Ajax response within a Jade template

I'm currently utilizing ExpressJS with the Jade template engine. My goal is to achieve the following: Within a Jade file, I need to extract a variable that will be used in a JavaScript file. This JavaScript file will then make an Ajax request to the ...

"Mastering the art of data retrieval in ReactJS: A guide to utilizing hooks in functional

I'm in the process of working with nextjs and I'm attempting to implement a "functional component" utilizing "hooks" for fetching data using "axios". However, I'm encountering the following error message: "AxiosError: Request failed with sta ...

Retrieving the attribute for a chosen value from an asp:RadioButtonList using jQuery

I am currently maintaining an old C# codebase and encountering an asp:RadioButtonList... <asp:RadioButtonList AutoPostBack="false" TextAlign="Right" RepeatDirection="Horizontal" RepeatLayout="Flow" runat="server" ID="radIncidentType" /> ...that is ...

Struggling to update a document fetched through a Mongoose model and handled as a promise

Check out update #2 for more detailed information I am encountering difficulties while trying to make a simple update to a document that has been retrieved by querying a container through a Mongoose model. The query using find has two populations, but oth ...

Creating a duplicate of a class and accessing its properties

Allow me to present what may seem like a Frankenstein's monster idea, but please hear me out. I have a specific type that I work with: export enum detailsDataTypes { MACHINE = 'MACHINE', USER = 'USER', ABSTRACT = 'ABSTRA ...

Three Conditions that Must be Fulfilled for Jquery CSS Selection

I have a challenge to create a CSS selector that demands the fulfillment of three specific criteria in order to trigger an action. $('div[class*="clickout"]') $('div[class*="preferred"]') $('div[class*="test"]') My goal is t ...

Repeating Sprite Textures in THREEJS

I have a sprite and I am attempting to make the texture repeat continuously. Despite using what I believe are the correct settings, it doesn't seem to be working as expected. Is there something I am missing? Here is the outcome I am seeing: https:// ...

Converting JSON formatting from Object to Array: A Comprehensive Guide

Encountering another issue with changing the JSON array output. Struggling to figure out why it's not rendering the other files. Providing a clearer explanation below: In my code snippet, when I use data[name] = {, each return name is rendered into ...

The issue of TypeError arising while invoking a method within TypeScript Class Inheritance

Currently, I am developing a Node.js application with TypeScript. In this project, I have a base controller class named BaseController and a derived controller called SettingController. The intention is for the SettingController to utilize methods from the ...

The Art of Using Ajax and jQuery in Joomla

Hello! I am currently facing an issue with the custom pagination for a Joomla component. I am attempting to create a list of user articles, displaying 3 posts per page without refreshing the webpage. After hours of searching for a solution, I decided to i ...

React Native: Struggling with Button Styling

I am relatively new to React Native, although I have experience with React in my professional work. I'm finding that applying styles to components in React Native is a bit different than what I'm used to. Specifically, I am struggling to apply s ...

How can we prevent AngularJS from continuously triggering a controller function with every input change?

Here is a simple TODO app created using angularjs. The functionality is working well, but I am facing an issue where angularjs calls the 'remaining' function on every keystroke in the input field!! Can you spot any errors in the code below? < ...

JavaScript Function Causes Applet's URLConnection.connect to Fail

My website features a Java Applet that needs to connect to the server. Interestingly, it successfully connects in JApplets @Override init(), but when called by JavaScript, it fails to do so. final URL url = new URL(SERVER_URL + action); System.out.println ...

the step-by-step guide to effortlessly uploading an image with ajax

How can I upload an image without the page refreshing? Whenever I hit submit to upload an image, my page still refreshes. It works fine when submitting plain text, so what could be wrong with my ajax code? test.php <div class="preview_d_p" id="preview ...

The conversion from JSON to a PHP API is facing obstacles

I'm having an issue with saving data when a button is clicked using Javascript and PHP. Button click: var xhr = new XMLHttpRequest(); var url = "savedata.php"; xhr.open("POST", url, true); xhr.setReque ...

Concealing a button within a specific interface

I am currently facing an issue with a data table that includes two control buttons: edit and save. My problem lies in hiding the save button on the initial preview. Basically, what I want to achieve is displaying only the Edit button on the first page. Wh ...

Steps for obtaining the current state array post re-ordering column in Angular datatables

I am facing an interesting scenario where I can successfully retrieve the current state of an array of columns using pure JS + jQuery, but unfortunately, the same approach does not seem to work in Angular 12! Despite going through the documentation for Ang ...

What is the best way to avoid the pipe symbol in jade formatting?

When working with jade, the pipe symbol (|) is utilized for displaying plain text. But what if you need to actually write it on the page? Is there a way to escape it in Jade? ...

How to retrieve the parent index from within a nested forEach loop in JavaScript

var game_board = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ]; (function iterate() { game_board.forEach((row, i) => { row.forEach((value, j) => { // accessing indexes i and j console.log(i, j); }); }); })() I have a two-dimens ...