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

115
Views
Passing a props value to an external function in Vuejs 3

I have a page showing details of a User and need to display the invoices belonging to 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>

I have a JS file that calls the API to fetch the data, imported in the invoice template. I am trying to get the vendorId in that JS file so that it can be passed as a param.

My invoice template looks like:

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

My useInvoiceList.js looks like:

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

How would I get the vendor ID in the fetchInvoices method?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One way is to set the variable value in the store and use it directly in your js file as you are already importing store in it another way you can pass parameters to fetchInvoices(props.vendorId).

about 4 years ago · Juan Pablo Isaza Report
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!