Error: Excessive recursion in Nuxt 3 module component

I am currently developing a Nuxt 3 module that includes a basic button component. The button is designed to toggle a boolean value when clicked, with the underlying logic stored in a separate file using pinia as a store.

Here is an example of the store code:

import { defineStore } from "pinia"

export const getLogic = defineStore('logic', {
  state: () => {
    return{
      status: false,
    }
  },
  actions: {
    flip() {
      this.status = !this.status
    },
  },
  getters: {
    getStatus() { return this.status }
  }
})

And here is the snippet for the button component:

<template>
  <button onClick="logic.flip()">
    <slot />
  </button>
</template>


<script lang="ts">
import { getLogic } from "../../stores/logic"

export default {
  setup() {
    const logic = getLogic()
    return { logic }
  } 
}
</script>

I am testing the functionality of this module within the "playground environment" by implementing the button component like so:

<template>
  <Button >
    Button
  </Button>
</template>

Upon clicking on the button component, I encountered an error message in the browser console:

Uncaught InternalError: too much recursion
    callWithAsyncErrorHandling runtime-core.esm-bundler.js:162
    callWithAsyncErrorHandling runtime-core.esm-bundler.js:174
    ...

This issue perplexes me, as there is no apparent recursion involved in my logic. How can I address or resolve this problem?

Answer №1

If that's the scenario, the correct syntax should be @click="logic.flip".

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

The ID that is received from props fails to show the associated information

I have created a component that contains another component. My goal is to display relevant details below when I hover over the name in the component. Although I have been able to pass the id successfully, the data associated with it is not meaningful. I am ...

The best way to avoid routing before certain async data in the Vuex store has finished loading

I am facing a challenge in my application where I require certain data to be loaded into the VueX store before routing can commence, such as user sessions. An example scenario that showcases a race condition is as follows: // Defined routes { name: &ap ...

Using a HTML tag within vue js

Is it possible to dynamically change a <p> tag inside my component to be an <h1> tag based on a prop? If so, how can this be achieved? <template> <p>Hello world</p> </template> ...

The system encountered an internal server error when attempting to locate and import the file

I seem to be having trouble loading components. I'm not sure what I missed connecting somewhere. <template> <MainLayout></MainLayout> </template> <script setup> import MainLayout from "../layouts/MainLayout.vue&qu ...

Exploring the option of integrating Vuetify snackbar as a universal custom component in Vue.js

I recently implemented a Snackbar to display success messages in Vue.js and now I want to create a global custom Snackbar component. <template> <div name="snackbars"> <v-snackbar v-model="snackbar" :colo ...

I am having difficulty retrieving information from the Laravel API

I am struggling to retrieve data from my Laravel application and display it in Vue CLI. While I can see the response, I am encountering difficulties when trying to show it in the Vue application. https://i.stack.imgur.com/tCgrd.png Whenever I attempt to f ...

Error alert: The "moment" reference is absent when utilizing moment in Laravel alongside Vue.js

Using Laravel 5, I have installed Moment.js through the npm install command. I am attempting to incorporate it into one of my views with Vue.js, but no matter what I try, I keep getting the error "moment is not defined." If I use require, I get "require is ...

Vue 3 list fails to refresh

Using an API, we are retrieving data: <script setup> import { onMounted, inject } from 'vue' let list = []; function initializeData() { axios .post("/some-link/here") .then((response) => { list ...

Activate Cross-Origin Resource Sharing for GraphQL requests

Currently working on a project that involves graphQL and spring boot. The API functions properly when using graphiQL, but there's an issue with CORS origin error when trying to consume it with Apollo vueJS. In the ProductQuery class which implements ...

Avoid VSCode from converting Vuejs code to vertical position upon saving

My Text Editor Formatting Issue ... is causing my code to be displayed vertically with too many lines. While it may make it easier to read, I find it tedious and unnecessary as it makes the file longer than needed. Could this be related to the Formatting ...

Managing the Response from Google Geocode API in a Vue JS Component

I am facing an interesting challenge. I have a scenario where users can choose between two options - using their current location or entering a zip code. When a user inputs a zip code, I need to make a call to the Google geocode API to retrieve the central ...

What is the best way to allocate mapState data in a list?

Currently, I'm tackling an apex bar chart project where I need to assign a list of mapState data into the apex series data. Here's the code snippet: <script> import { mapState } from 'vuex'; export default { data: () => ({ ...

When the page is refreshed, the ID passed through params disappears

One of the challenges I am facing involves a component called Subscribers that receives props through params from another component known as Details. These props are used to make an API call and retrieve a list of subscribers, which functions correctly. H ...

struggling with managing an array of Vue3 refs

Having an issue with handling vue3 refs, specifically when retrieving data from Firestore. When logging the [documents], everything seems to work fine. However, I run into errors when trying to access values from an array within a document. For example, ...

Exploring the functionality of publicRuntimeConfig in Nuxt plugins

I have developed a new Vue socket.io plugin called @/plugins/socket-io.js import Vue from 'vue' import VueSocketIO from 'vue-socket.io' Vue.use( new VueSocketIO({ debug: true, connection: process.env.SOCKET_IO_CONNECTION, } ...

Opt for router-link over web route when working with Laravel

While working with Laravel 9 and Vue 3, I encountered a peculiar issue. When navigating to a link by clicking on the menu, everything worked as expected. However, if I tried to access the same link by directly typing the URL or refreshing the page, I would ...

Press the div, excluding the button - Vue

I have a basic div that spans 100% of the width, containing a button inside. The issue I'm facing is that when I add a click event to the div, the entire div becomes clickable (including the button within it). What I want is for the whole div to be ...

Having difficulties integrating a login solution due to an error saying "eslint Promise executor functions should not be async no-async-promise-executor"

I'm currently working on integrating a login solution into my Vue app using the JWT Authentication plugin. While I have a test solution that is functional, I'm facing an issue in my main branch where the eslint version seems to be causing an err ...

Webpack fails to resolve paths provided by a JavaScript variable

I am currently developing an application using vue and ionic, but I have encountered an issue with loading assets as the paths are not resolving correctly. <template> <div id="index"> <img :src="image.src" v-for="image in image ...

Utilizing Vue Router for service integration

I have configured my vue router for external components and services, setting it up as follows: /* Router.ts */ import { myRoute } from './views/myRoute.vue' const router = { routes: [ { name: 'my-router', ...