Creating a new row in a Vue component table

I'm having trouble with creating a table using a Vue component. My goal is to add rows to the table by clicking on the "Add" button, but it doesn't seem to be working correctly. Every time I click the "Add" button, I see the row being added to the table briefly before disappearing again. I suspect that this issue is related to Vue reactivity, but I can't pinpoint where I've gone wrong. Can someone please help me identify my mistake?

<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>Titles</title>
</head>
<body>

<form id = "app" >
    <conf-table v-on:add-panel="addPanel" :table = "tabledata" ></conf-table>
</form>

<template id = "table-template">
    <div>
        <table class="lowertable">
            <tr>
                <th width="220"><div id= "ConvHeader">No.</div></th>
                <th width="130" >Panel</th>
            </tr>
            <tr v-for="(elem, index) in table" :key = "index">
                <td >{{elem.id}}</td>
                <td ><input id = "convConfTable_nr" name="" type="search" :value=elem.name /></td>
            </tr>
        </table>
        <input v-on:click="addPanelChild" class="button" name="button" type="submit" value="Add" />        
        </div>
</template>

</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script th:inline = "javascript">
    

    var tableData = [];

    Vue.component('conf-table', {
        template: "#table-template",
        props: ['table'],
        methods: {
            addPanelChild: function() {

                this.$emit("add-panel");
            },
        }});

    var vueApp = new Vue({
        el: "#app",
        data: {
            tabledata:  tableData,

        },
        methods: {
            addPanel: function() {

                var panel = {
                    id: 77,
                    name: "Qwerty"
                };

                this.tabledata.push(panel);
            }
        }
    })  

</script>

</html>


Answer №1

By simply replacing

<form id = "app" >
with
<div id = "app" >
, the issue was successfully resolved. It seemed that the Vue application was malfunctioning when it was mounted on a <form> tag for some unknown reason.

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

Using the .map method to index an array is causing issues in Node.js

Hey everyone, I'm struggling to properly index a JSON array using the map function. It seems like my code isn't quite right. This is what I have: var entireHTMLssssq = lloopmois.map((result, index) => `<div id=${index} style="position: a ...

Utilizing Lambda to Analyze PDF Documents with AWS Textract

Struggling with implementing Textract in Lambda to analyze PDF documents using JavaScript. Any assistance would be greatly appreciated. Below is the code snippet: const AWS = require("aws-sdk"); AWS.config.update({ region: proces ...

Adding HTML content to a container in Angular 2 using TypeScript

My goal is to add some HTML content to an element. After researching various solutions online, I came across many confusing and ineffective methods. To achieve this using JavaScript, I can use the following code: var d1 = document.getElementsByClassName(& ...

Interactive Widget resembling Messenger for Google Site

Hey there, I'm working on creating a floating widget similar to Facebook Messenger for my Google site. However, I've encountered an issue where it only stays fixed at the very bottom of its section. Below is the code I'm currently using: &l ...

Top method for incorporating Ember.js with outside code (such as Android's WebView)

Can someone advise on the best approach to developing an Ember.js app that needs to interact with external code, such as being called from an Android app through a WebView or other sources outside of the Ember Application's scope? In such cases, havi ...

Retrieving Angular URL Parameters Containing Slashes

I'm currently in the process of developing a single page angular application. This app retrieves a token from the URL and then sends it to an API. At the moment, my URL structure is as follows: www.example.com/?token=3d2b9bc55a85b641ce867edaac8a9791 ...

When the overflow is set to visible, the background color vanishes

Here is the CSS code I have written; #container { width: 1300px; background-color:green; margin:0 auto; overflow:hidden; } #menu { float:left; width:20%; background-color: yellow; } Even after extensive searching on Google, I ...

Vue render error: "Array length is invalid"

Using Vue v2.* in my project, I implement a v-for range with computed properties. Computed Properties computed: { numberOfPages() { const result = Math.ceil(this.collection.total / this.collection.per_page) return (result < 1) ? 1 ...

Is there a way to restrict a forEach loop so that it only runs 16 iterations?

I'm looking to limit the number of results shown in a forEach loop to only 16. Is there a way to achieve this? <div class="events-list" data-bind="if: (typeof(Events) != 'undefined')" style="padding-top:5px; padding-bottom:5px;"> ...

Switching between a single checkbox and a group of checkboxes: A step-by-step guide

My goal here is to design a group of checkboxes. The "Search everywhere" option is initially checked by default. If you check any other checkbox, the "Search everywhere" box automatically unchecks. You're allowed to check multiple checkboxes, but once ...

What is the best way to display a JavaScript loop on a webpage instead of just in the console?

As a beginner in programming, I have taken on the challenge of creating my own FizzBuzz program. The goal is to write a program that displays numbers from 1 to 100. However, for multiples of three, it should output "Fizz" instead of the number; for multipl ...

A Guide on How to Sort and Tally Items in a JSON Data Set containing Numerous Objects using JavaScript

I have recently started learning javascript, and everything was going well until I encountered this issue. I need to reformat a JSON file in the following structure: { firstName: "Joel", lastName: "Munz", total: 154, transaction: "111111", ...

Encountering the `undefined is not a function` error message when trying to map the response data from an API call within a

While working with an API, I am saving the result in a state called shift and here is the outcome: [ { "id": 123, "status": "created", "expected": { "end_time": " ...

navigation bar directing to the wrong destination

My landing page has attached pages like landing/gothere and /another. The issue arises when I try to navigate from /another to landing/gothere. I fetch landing information using an API, but there's a delay when I click on the navbar link. The page loa ...

Tips for preventing a React component from re-fetching data when navigating back using the browser button

In my React app using Next.js and the Next Link for routing, I have two pages set up: /product-list?year=2020 and /product-list/details?year=2020&month=4 Within the pages/product-list.js file, I am utilizing React router to grab the query parameter ye ...

Monitor changes in Angular Reactive forms to retrieve the field name, as well as the previous value and the current value of the field

this.formData = this.fb.group({ field1: '', field2: '' }); this.formData.valueChanges.pipe(startWith(null), pairwise()) .subscribe(([previous, current]: [any, any]) => { console.log('PREVIOUS', previous); co ...

Enhance the functionality of CKEditor Link feature to emulate the seamless linking experience of Gmail, eliminating

Looking to enhance the CKEditor Link feature to function like Gmail's 'Insert Link' where clicking on it automatically converts text to a link without needing to provide a URL in a popup. Any suggestions? ...

Ways to dynamically incorporate input fields into a form

My current project involves managing an Asset Management system for a company with multiple locations. This system has the capability to return unused asset items back to storage. I am faced with the task of returning a large number of items, which requi ...

Integrating Vue Components into a React Micro Frontend with the Latest WebPack Version

Recently, I've delved into the world of micro frontends. To get started, I created a React micro frontend project named Micro-Shell-App using npx create-mf-app. Following that, I embarked on creating another project for Vue micro frontend called Secti ...

Creating Docker images in a lerna monorepo without the need for publishing

In the context of Lerna monorepos, the primary goal is to facilitate branch building and deployments. The challenge arises from the fact that Lerna monorepos either consolidate dependencies in NPM or utilize yarn workspaces to achieve the same outcome, re ...