There seems to be an issue with the reactivity in the Vue Composition API

Currently utilizing Vue2, Vuetify, and the Vue Composition API (@vue/composition-api). Encountering an issue with the reactivity of the composition API.

Let's delve into some code snippets:

---- companies.vue ----

<template>
  ...
  <v-data-table
    :headers="companiesHeaders"
    :items="companies"
    :loading="loadingCompanies"
  />
  ...
</template>

<script>
...
import { useCompanies } from '@/use/companies'

export default {
  setup: (_, props) => {
    ...
    const {
      companies,
      loadingCompanies,
      getCompanies
    } = useCompanies(context)

    onMounted(getCompanies)

    return {
      ...,
      companies,
      loadingCompanies
    }
  }
}
</script>

---- @/use/companies.ts ----

import { ref } from '@vue/composition-api'

export const useCompanies = (context: any) => {
  const { emit, root } = context

  const companies = ref([])
  const loadingCompanies = ref(false)

  const getCompanies = async () => {
    if (loadingCompanies.value) { return }

    try {
      loadingCompanies.value = true
      companies.value = (await root.$repositories
        .companies.getCompanies()).data

      console.log(companies.value)
      // The log successfully displays the company list upon reception
      // However, post-async function completion, companies and loadingCompanies fail to update automatically
    } catch (err) {} finally {
      loadingCompanies.value = false
    }
  }

  return {
    companies,
    loadingCompanies
  }
}

Experimented with both ref and reactive, yet encountering issues with reactivity within companies.vue components.

Answer №1

The problem has been successfully resolved. The root cause was identified as having separate instances of the company variable created in two different locations (one for the create company dialog and one for the table), which meant that changes made in one location (the create company dialog) did not impact the other (the table). Thank you for your assistance.

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

Customize the drawer background in Vue Material

Recently, I developed a vuejs application incorporating Google's material design components. I've been exploring options to customize the background color. <template> <div class="page-container"> <md-app> ...

Obtained a ZIP file via CodeSandbox that contains a Vue.JS webpage. However, the index.html file yielded an

I have created my first ever Vue.JS / Vue2Leaflet app. It runs perfectly fine on codesandbox.io. However, when I download the ZIP file and try to open the index.html file, it appears blank. Is there something specific that needs to be done to make it work, ...

How to apply props conditionally in VueJS?

I have a component called blogPost (Component A) that is imported in another component named B. When a button in Component B is clicked, Component A opens in a modal. There are two different use cases for this scenario. 1. One case requires passing 2 prop ...

Why doesn't Vue's computed method call the 'get' function after setting a dependent value in the 'set' function

Allow me to explain how I define a computed value: Template : <date-picker v-model="rangeDate" type="date" format="jYYYY/jMM/jDD" display-format="jYYYY/jMM/jDD" input-c ...

Inertia: Refresh the page with new data without altering the current scroll position

In my application using Inertia/Laravel/VueJs, I have a page displaying numerous posts where each post can be marked as completed. Upon marking a post as completed on the front-end, a CSS class should toggle to indicate completion. The desired behavior is ...

Generate a new span element within a div element programmatically using Vuex

I have integrated an existing web application developed using vue.js. Below is the code snippet: function () { var e = this, t = e.$createElement, n = e._self._c || t; return e.messag ...

Is it possible to import Vue directly from the "/path/to/vue.js" file without using npm or NodeJs?

Is it possible to build a web app using just a single index.js file and importing other available files like shown in this image: https://i.stack.imgur.com/02aFF.png encountering the error message: import not found: default Do you have to use Vuejs wit ...

Implementing Firebase Firestore Timestamp Function

Encountering an issue while attempting to record the submission time for filtering purposes in Firebase. Allow me to present what I currently have (in a functioning state). -- At the moment, I have a form where users provide information that is then pus ...

What is the best way to associate a style with my v-for loop in this specific instance?

Why is there no styling applied to the td element when using steps.name? The code seems correct and I see no errors in the dev tools. <!-- Template --> <td v-for="steps in item.steps" v-bind:style="steps.name"> {{ steps.name }} </td> / ...

What is the best way to use arrow functions in VueJS?

Here is how my method in vue currently looks: methods: { setDate: async function () { console.log(this.modal) } } I want to convert it into an arrow function. I tried the following approach: methods: { setDate: async () => { ...

"Using Vuejs to pass data from Parent to Child component through v-for loop

I'm experiencing an issue with my Bootstrap Collapse and Vuejs integration. I seem to be having trouble accessing item data in the child component. Any assistance would be greatly appreciated. Here is the HTML code snippet: <div class="panel-grou ...

Exploring the Power of Ajax Interceptor in Framework7-vue-cli

I have a challenge where I need to redirect all ajax requests with a status code of -1 in the response to the login screen. Despite my efforts, I am unable to monitor it. What steps should I take next? Appreciate your help. My approach: app.js Framework7. ...

Mistakenly appearing at the top of the window instead of the bottom of the window

Utilizing Vue.js to fetch resources from a Laravel API periodically and paginate(), after retrieving the initial 10 instances, I aim to get the next 10. Here's how my method looks: scroll () { window.onscroll = () => { let bottomOf ...

Oops! It seems like there was a mistake. The ReferenceError is saying that Vue is

I've been working on creating a new app, but I keep running into an issue. Unidentified Reference Error: Vue is not recognized. <template> <v-app> <div id="example-1"> <v-btn v-on:click="counter += 1">Add 1</v-bt ...

"Vue.js: The Ultimate Guide to Event Management and Data Handling

I recently started learning Vue.js and I'm having some difficulty with my coding exercises: The task is to have a menu button that opens a dropdown box when clicked, and when any selection is made, it should go back to the menu button. index.js cons ...

Storybook is pulling fonts from an incorrect location on the server

Regrettably, I am facing an issue where the fonts do not load when accessing a page with Quasar integration. In the Developer Tools, it shows a path error like this: http://localhost:6006/undefined/node_modules/@quasar/extras/roboto-font/web-font/KFOmCnqEu ...

Inertiajs - Seamlessly transition to a different page within the same environment

Is there a way to navigate between pages on the client side in Laravel and InertiaJS without using inertia.visit()? I am curious about how to switch pages solely within the client, without having to communicate with the server. Can props be specified fro ...

Delivering resources through the Nuxt configuration file

https://i.stack.imgur.com/2OWdE.png I came across a bootstrap template online that I want to customize for my Nuxt project. I have stored all the bootstrap files in the static folder. Within the nuxt.config.js file: module.exports = { /* ** Headers ...

In Vue templates, any spaces or line breaks between element tags are not disregarded

<template> <div> <p> hello universe </p> </div> </template> Result: <p> hello universe </p> We need to get rid of the unnecessary spaces before and after "hello universe" ...

Using Webix in conjunction with Vue.js to make method calls

Is there a way to invoke the method storeNewOrder in the onAfterDrop event from the Webix component? Neither this.$emit.storeNewOrder() nor storeNewOrder() seem to be effective. export default { template:"<div></div>", pro ...