How to Transfer a Props Value to an External Function in Vue 3

I'm currently working on a page that displays user details and need to also show the invoices associated with that user.

<template>
    <div>
        <div>
            // Child component one .....
        </div>
        <div>
            // Child component two .....
        </div>

        <div>
            // Invoice component one .....
            <invoice-list :vendor-id="vendorData.id"/>
        </div>
    </div>
</template>

In order to fetch the data from the API, I have a JS file imported into the invoice template. However, I'm facing a challenge in passing the vendorId as a parameter in the JS file.

Below is a snippet of the invoice template:

<template>
    <div class="wrapper">
        <!-- Table Container grid -->
        ---------
        ---------
        ---------
    </div>
</template>

<script>
import { onUnmounted } from '@vue/composition-api'
import store from '@/store'
import useInvoicesList from './useInvoiceList'
import invoiceStoreModule from '../invoiceStoreModule'


export default {
  props: {
    vendorId: {
      type: String,
      required: false,
    },
  },
  setup(props) {
    
    const {
      fetchInvoices,
      refetchData,
    } = useInvoicesList()

    return {
      fetchInvoices,
      refetchData,
    }
  },
}
</script>

Here is a glimpse of the useInvoiceList.js file where I am struggling to access the vendor ID:

import { ref, watch, computed } from '@vue/composition-api'
import store from '@/store'

export default function useInvoicesList() {

  const refInvoiceListTable = ref(null)

  const fetchInvoices = (ctx, callback) => {
    store
      .dispatch('app-invoice/fetchInvoices', {
        q: searchQuery.value,
        **/*This is where I need the vendor ID*/**
      })
      .then(response => {
       
      })
      .catch(() => {
        
      })
  }

  return {
    fetchInvoices,
    refInvoiceListTable,
    refetchData,
  }
}

Any suggestions on how I can access the vendor ID in the fetchInvoices method?

Answer №1

To solve this issue, consider setting the variable value within the store and accessing it directly in your JavaScript file. Alternatively, you can pass parameters to the fetchInvoices function using props.vendorId.

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

Receiving a notification when attempting to log in with incorrect credentials

I am currently working on an Angular login page implementation using a username and password setup. When the user enters incorrect credentials, I want to display an alert message indicating the same. Here is the HTML code snippet for the form: <form [f ...

Enhance the appearance of elements within an iframe by applying styles using VueJS

I am facing a dilemma with my modal screen that contains an iframe for sending out agenda items. Unfortunately, I'm unable to customize the styling of the iframe itself as it's being used elsewhere in the application. However, I need to apply som ...

Importing three.js using ES6 syntax

When it comes to working with ES6, my workflow involves using Babel and babel-plugin-transform-es2015-modules-system.js specifically to transform module import/export for compatibility with system.js. I rely on a "green" browser for most ES6 features excep ...

Moving between different perspectives within a single-page backbone application

I am interested in incorporating dynamic transitions similar to the ones showcased on this website into a single-page backbone application. However, I am unsure of where to begin. Do I need to modify how I initialize my views (currently using a standard sw ...

Eliminate the need for require statements in TypeScript-generated JavaScript files

I am working on a website project and utilizing TypeScript for development. While using the tsc compiler, I noticed that all my JavaScript code compiles correctly. However, when I include an import statement in my TypeScript files, it gets compiled into J ...

Fetching data from a database for Vue.js using the Summernote editor

I previously inquired about integrating summernote with vue.js and received a helpful response here. It worked seamlessly with v-model binding. However, I encountered an issue when attempting to load data from the database for an edit page. The data was n ...

Pass the output of one function as an argument to another function in a Node.js Express application

I'm having trouble retrieving the value declared in the first function CreateTag and using it as a variable in the second function CreateStream. Despite working with nodejs Express, I've attempted to use RETURN without success. I've tried v ...

Can PushState be used to Ajaxify CSS files?

Currently, I am in the process of developing a basic website and have decided to incorporate the Ajaxify library for seamless page transitions. One challenge I have encountered involves the combination of global CSS files (applied throughout the entire sit ...

Ways to resolve the issue: "internal/modules/cjs/loader.js:638 throw err; ^"

I am encountering an error when trying to run my Vue.js project using npm on localhost:8080. Is there a solution to resolve this issue? This error specifically occurs when I attempt to install node_modules and package-lock.json in my Vue folder, which inc ...

Displaying a loading spinner image as PHP script runs

Hey there! I've been experimenting with using a script to show a loading bar while my PHP code is running. I followed the instructions on this website, but even after following the exact steps, my loading bar still isn't showing up. Any suggestio ...

Is UseEffect selectively triggering specific components?

I am attempting to ensure that each time my search field changes, the code within useEffect is executed. Strangely, only console.log('hi') seems to be running while the other code is not. I am struggling to understand why useEffect is choosing t ...

The initial AJAX GET request is successful, however subsequent clicks do not trigger the call

I have been encountering an issue with my JavaScript where an Ajax call that used to work perfectly fine suddenly stopped working. I have not made any changes to the code that could cause this problem, but something is definitely going wrong. The Ajax call ...

Sending data from Node.js to PHP using POST method

Currently, I am attempting to send data from a Node.js application to a PHP script using a POST request. I am in the process of creating a proof of concept, but I am encountering an issue where the data does not seem to be reaching the PHP side. Although t ...

Creating a JQuery statement to conditionally change CSS values

Is there a way to determine if a div element with a CSS class of "x" has a height set to "auto"? If so, I would like a jQuery script to remove the CSS class "a" from all elements with the class "y". If not, the script can remain unchanged. Thank you. ...

Having trouble with d3 / svg layering when introducing new nodes overtime

Struggling with a frustrating issue on my d3 force directed map project. Initially, I render the necessary nodes and links, then periodically check for updates through AJAX. The problem arises when adding new nodes and links – they appear over existing c ...

The Redux Toolkit Slice Reducer fails to function properly when incorporating an extra Reducer that is not compatible

I am relatively new to the world of Redux and have been attempting to use RTK right from the start. It has been quite a challenging and confusing experience for me so far. Recently, I decided to include a standard Reducer instead of an extraReducer in my ...

Integrate user interface functionality within the server component in NextJS

When considering the Server Component located in the new app/ directory within NextJS: export default async function RootLayout({ children }) { const categories = await getCategories(); // const [navigation, setNavigation] = React.useState('hidde ...

Include new items in the li tag using JavaScript

Hello, I am looking to dynamically add elements to an LI element when a link is clicked. I have successfully added elements to a DIV using the following code snippet: I came across a similar question on Which "href" value should I use for JavaScript links ...

Discover the XPath of a post on a Facebook page with the help of HtmlUnit

I am trying to fetch the xpath of a Facebook post using HtmlUnit. To better understand my goal, you can check out these two related questions: Supernatural behaviour with a Facebook page HtmlUnit commenting out lines of Facebook page To replicate my pro ...

Is it necessary to implement clustering for each route in an Express.js application?

Currently, I am utilizing the cluster module to fork my application within my index.js, which serves as the primary file in the root directory of my website. My application consists of numerous routes. Should I incorporate the cluster code to encapsulate a ...