Update the data table after a new file has been uploaded

As a novice web developer, I embarked on my first project using Vue.

In this project, I created a form for file uploads in Vue 2 and Laravel.

If you want to take a look at the full code:

The overall functionality works well, but I have run into a small problem with reloading the data-table-user-files after uploading files.

Here is the code snippet for the modal containing the file uploader:

 <!-- Modal code snippet goes here --> 

I need an action to refresh the data-table-user-files component after the message "Success File added successfully!" How can I achieve this reload of the files list?

I've attempted to handle this issue through the following function:

 // Function definition for handling file list retrieval 

However, despite my efforts, it seems like something isn't quite right. Can someone provide me with guidance on how to fix this issue? Your help would be greatly appreciated.

Answer №1

Modifying the URL to initiate a re-fetch of the information:

<template>
<data-table-user-files
                  :fetch-url="datatTableUrl5"
                  :columns="['id', 'description', 'file_category','user_id' ]"
                  :headers="{'id': 'ID','description': 'Opis','file_category': 'Kategoria','user_id': 'Twórca'}"
                  :routeName="routeAddName5"
/>

<script>
export default
{
  data()
  {
    return {
      triggerRefetch: 0,
    };
  },
  computed:
  {
    datatTableUrl5()
    {
      return `https://my.api.example.com/api/endpoint?t=${triggerRefetch}`;
    },
  },
  methods:
  {
    filesSuccessfullyUploaded()
    {
      this.triggerRefetch++;
    },
  }
}
</script>
import Axios from 'axios';

export default
{
  props:
  {
    fetchUrl:
    {
      type: String,
      required: true
    },
  },
  data()
  {
    files: [],
  },
  watch:
  {
    fetchUrl:
    {
      immediate: true,
      handler()
      {
        this.getFilesList();
      }
    }
  },
  methods:
  {
    getFilesList()
    {
      Axios.get(this.fetchUrl).then(response => this.files = response.data || []);
    }
  }
}

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

Utilize the event bus by calling `this.$root.$emit` command

I recently implemented a basic Event bus in my application to dynamically change styles on a page, and it's functioning correctly. The event bus is triggered using the $emit and $on methods as shown below: EventBus.$on and EventBus.$emit('call ...

Is there a way for the React select component to adjust its width automatically based on the label size?

After defining a React select component, it looks like this: <FormControl> <InputLabel id="demo-simple-select-label">Age</InputLabel> <Select labelId="demo-simple-select-label" id=&quo ...

What is the best way to trigger a data update in the parent component when the child component in a Vue component is clicked?

Here is the structure of my first component (child component) : <template> ... </template> <script> export default { ... methods: { addPhoto() { const data = { id_product: this.idProduc ...

Listening for Vue events when the mouse is held down

Is there a way to adjust the boolean value when the mouse click is pressed and released? In my Vue project, I currently have v-on:mousedown="hold = !hold", but this setup toggles the boolean instead of requiring the user to hold down the click. ...

Understanding JavaScript Prototypal Inheritance within ES5 Classes

I've been working on creating an XMLHttpRequest interceptor for Angular, encountering a roadblock when trying to intercept a third-party library that uses the XMLHttpRequest API. Although the solution below is functional, I've run into issues wit ...

Tips for overcoming the Chrome Extension Error related to the "script-source 'self'" issue

I've been developing a Chrome extension that uses goo.gl to shorten URLs. Here is the code I'm currently working with: $("#ajaxfiller").text(""); //Retrieve entered URL var longUrl = $("#input2").val(); longUrl = '"' + longUrl + &a ...

Ways to determine if prototype methods vary

Is there a technique to verify if functions are distinct despite originating from the same prototype? I'm inquiring because I want to save functions in an array, and when attempting to delete one, it removes all functions due to sharing prototypes. ...

In an Electron-React-Typescript-Webpack application, it is important to note that the target is not a DOM

Rendering seems to be working fine for the mainWindow. webpack.config.js : var renderer_config = { mode: isEnvProduction ? 'production' : 'development', entry: { app: './src/app/index.tsx', //app_A: './src/a ...

Exploring the concept of reflection in JavaScript and jQuery

Here is a javascript object I have: person.Name = "John"; person.Nick = "Smith"; person.Info = "hi there"; In addition, I have some HTML elements as shown below: <input id="Name" /> <input id="Nick" /> <input id="Info" /> My question ...

Please refrain from clearing the text field as it will delete the input value

I feel like I must be overlooking something really minor because I just can't seem to find it! I've been attempting to sanitize the text input by setting the state to ('') and while it clears the variable, the HTML input keeps displayi ...

Why is my React build's index.html coming up empty?

I've been working on a React app using Snowpack, and everything seems to be in order. The build process completes successfully, but when I try to open the index.html file from the build folder, the page appears blank. To temporarily resolve this issu ...

Identifying the FireOS version using JavaScript

Can JavaScript be used to determine the version of FireOS that a Kindle device is running when accessing your website? ...

Express Power Tool - Error: app.set function is undefined

My journey with creating an API using Node/Express began with a solo endeavor to learn the basics in a 'naive' manner. The initial setup worked smoothly, prompting me to experiment with express-generator. Upon completion of the setup process, th ...

What is the best way to retrieve the root binding node from a viewmodel in order to apply jQuery.blockUI when performing an AJAX post request?

Within my code, I have a designated DIV element that serves as the root node for applying knockout bindings like so: ko.applyBindings(viewModel, document.getElementById('myContainerDiv')); In all of my viewmodel types, there is a generic post m ...

I encountered an issue in VueJS where it cannot find the property 'fn' of undefined

I am currently working on a project using VueJS and I have encountered a problem. My goal is to integrate owl.carousel, so I proceeded by installing it through the following command: npm install --save owl.carousel After installation, I imported it into ...

Insert a character or icon into a :value

I am faced with a situation where I have two input text fields, each being assigned a value from an array stored in a state. The array contains two elements, one for each input field. However, I wish to append a symbol such as % or some additional text at ...

Ways to extract link value in Angular

Is there a way to extract a value from a link using Angular 4? I have used *ngIf and would like to display a div based on the value within the link. <div *ngIf="obtain the value from the current href"> ...

When using $resource.save, it returns a "Resource" instead of just an ID

For some reason, I am struggling with a seemingly simple task and cannot find a solution by going through documentation or other Angular related questions on SO. I may not be the brightest, so I could really use some help here as I am feeling stuck. Take ...

A step-by-step guide on implementing one-way drag functionality in two lists using Vue.js

I've implemented the vuedraggable library for creating draggable items(https://github.com/SortableJS/Vue.Draggable) My goal is to have two draggable lists where dragging is only enabled from list1 to list2. I want to disable drag from list2 to list1 ...

How can we fix the null parameters being received by the ModelPage function?

I've been learning how to successfully pass values to a Post method using AJAX in .NET Core 6 Razor Pages, but I am encountering some difficulties. Below are the relevant codes: Front end: function calculateSalary() { var dropdown = document.get ...