I'm looking for a method to dynamically update my component without the need to refresh the entire page. Can

I created a Vue component that constructs the card and within it, I have another component to which I pass data using a prop. Currently, I am using Swal as a popup to add a new project to the database. However, after adding the project, I have to manually refresh the page to see the updated data. The main reason for choosing Vue was to avoid refreshing the page to view updated data, but unfortunately, I haven't been able to solve this issue.

Below is my Projects.vue file:


import ProjectItem from './Projects/ProjectItem.vue';
export default {
    name: "Projects",
    components: {
        ProjectItem
    },
    data() {
        return {
            projects: []
        }
    },
    methods: {
        getProjects () {
            axios.get('/api/projects').then((res) => {this.projects = res.data});
        },
        addProject() {
            // Swal implementation here
        }
    },
    mounted () {
        this.getProjects();
    }

In the template of my Project.vue, I bind it to ProjectItem like so:


<div class="table-responsive border-top">
    <table class="table card-table table-striped table-vcenter text-nowrap">
        <!-- Table content -->
        <project-item v-bind:projects="projects" />
    </table>
</div>

Here is my ProjectItem.vue file:


<template>
    <!-- Template content -->
</template>
<script>
export default {
    name: "ProjectItem",
    props: ["projects"],
}
</script>

Answer №1

Make sure to add the most recent project to the products array.

If you have the capability to modify the backend code, consider updating the response to incorporate the new project.

this.projects.push(response.project);

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

Add axios requests to the axios.all array

Good evening. I am currently trying to insert an array into the axios.all([]) structure! This is the code snippet I am working on: app2.js new Vue({ el: '#central', data: { estilo: 'resize:none;text-align:center;color: ...

An error occurred while defining props due to a parsing issue with the prop type. The unexpected token was encountered. Perhaps you meant to use `{`}` or `}`?

const dataProps = defineProps({ selectedData: <Record<string, string>> }); Under the closing bracket, there is a red line indicating: Error: Unexpected token. Consider using {'}'} or &rbrace; instead?eslint Expression expecte ...

The function did not execute properly, resulting in the express route returning no value

Encountering some issues with Express routes that are behaving inconsistently despite having identical code execution. The goal is to have a client application make API calls like this: async search(){ const query = this.$refs.searchInput.value; ...

I am interested in incorporating pinia state management into my Vue 3 project

I'm currently working on implementing pinia state management in Vue 3, but I've encountered the following error: Module not found: Error: Can't resolve 'src/stores/cart' in 'C:\Users\Ali Haider\theme-project&b ...

Troubleshooting: Issue with v-link to classname in Vue.js

This is the code I am working with: <div v-link="'/work/' + {{data.useClass}}" class="itemImg {{data.useClass}}"> When rendered in the browser, it looks like this: <div class="itemImg x50"> The expectation is that class="itemImg { ...

The vue-cli 3.0 command runs on multi (webpack)-dev-server/client at the URL http://10.0.68.112:8080/sockjs-node, using webpack hot dev-server from ./src/main.js

While working on the project, I encountered an error when running vue-cli-service serve because the main.js file is not located in the src root directory. The error message reads as follows: * ./src/main.js in multi (webpack)-dev-server/client?http://10 ...

Not prepped for EasyFB

Currently incorporating Easy Facebook for AngularJS (https://github.com/pc035860/angular-easyfb) into my project and encountering some inconsistencies in its functionality. Upon inspecting with console.log(ezfb);, I discovered the following: https://i.sta ...

Can you provide some insight on the app.vue file within vue?

When working with Vue, declaring text.vue in a file named app.vue will result in the contents of text.vue being applied to all pages. However, there may be certain pages where you do not want text.vue to be applied. Is there a way to achieve this? app. ...

Issue with Axios GET request due to CORS restrictions

I am currently developing a VueJS application and I am trying to integrate the Yahoo! Shopping API (documentation: ) in order to retrieve products based on their barcode. However, I am encountering a CORS error that is preventing the API request from being ...

Using Laravel 8 to create connected dropdown menus with the power of Ajax

Struggling with setting up a dependent dropdown menu in Laravel 8 using Ajax. The first dropdown works fine, but the next two don't display any options. Being new to Laravel, I'm having trouble pinpointing the problem areas. Seeking assistance to ...

Storing row details in Vue.js based on selected options from a dropdown menu

Displayed below is my code that generates a dynamic table. I am looking to save specific rows based on the selection made from a dropdown menu and then clicking on an update button. <b-field> <b-select name="contacted" id="" ...

Incorporating an ordinal value into the Laravel Model

As a beginner web developer, I am currently working on a project using Laravel 7 and maatwebsite/excel. Here is the code snippet I have: namespace App\Models; use App\Models\Reservation; use Maatwebsite\Excel\Excel; use Maatwebsi ...

What is the best way to send a JSON object in Vue.js?

<template> <div id="app"> <div id="bee-plugin-container"></div> </div> </template> <script> // import axios from "axios"; // import Bee from "@mailupinc/bee-plugin"; import $ from 'jquery' ...

Tips for resolving the "semicolon expected" alerts in your CSS code (css-semicolonexpected)

Having some trouble with using the Tailwindcss @apply directive within a <style> tag in a Nuxt.js Vue file. It seems to be working fine, but those annoying red squiggly lines keep popping up. Any help would be greatly appreciated! Thank you! Take a ...

Encountering an issue while invoking the helper function in Vuejs

Main view: <script> import { testMethod1 } from "../helper"; export default { methods: { init(){ console.log("Res:", testMethod1()); } } } </script> Helper: import DataService from "../services/data. ...

Best practices for passing multiple values with keys in vue.js when constructing URLs

I am working with this data containing various attributes: for(var k = 0;k<this.form.fields.length;k++) { this.dynamic_fields.push({attribute_id:attributes[k].id,value: attributes[k].value}) ...

How can Vue detect modifications made in the edited field?

I am facing an issue with tracking changes in a specific object. Here is the structure of the object: users: { email: '', password: '' } My goal is to detect any edits made to the keys within the users object and store the key ...

Tips on accessing the v-model value with a parameter in VUE

Looking to access the v-model value using a parameter, I attempted the following code: <template> <div v-for="(item, idx) in data"> <input :id="item" :v-model="item"></input> <button @click=&q ...

Can you demonstrate how to incorporate a new line within a for loop?

I have an array of letters and I need to display them on the screen using a for loop. My goal is to make every sixth letter appear on a new line. Here is the code snippet: https://i.stack.imgur.com/lHFqq.jpg <script> export default { data() { ...

Integrate AngularJS with Laravel for efficient routing management

In my current web app project, I am utilizing AngularJS and Laravel for the development. Below is a breakdown of how my routing is set up: AngularJS: angular.config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRo ...