Adding or removing rows within an array in a hybrid Vue project - a step-by-step guide

Recently, I created a small web application to assist in organizing my project ideas. Check it out here: https://codepen.io/aibrindley/pen/ELXajM

Now, I am working on enabling users to add items to the array directly from the interface. It would also be convenient if they could remove items as well.

The code I've implemented is a combination of different techniques utilizing Vue.

One specific area to focus on is how product names are set and displayed:

<td>{{ product.name }}</td>
<td><input id="iname"/></td>

When a user clicks the button, the item gets added to the list:

function addItem() {
  var iname = document.getElementById("iname").value
  products[products.length + 1].name = iname

I understand that the array should ideally be set within:

new Vue({})

However, when I tried this approach, calculating the total column became unsuccessful...

If anyone could provide assistance, I would greatly appreciate it! There must be a simple solution that I'm overlooking.

Update: With the help of @Sphinx, the codepen has been updated and is now functioning correctly. Look for @click="addItemByVue();" in the HTML and addItemByVue in the JavaScript section.

Answer №1

experiment with it:

generated: {
  window.addProduct = this.addProductByVue.bind(this)
}

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

Unable to display Laravel Vue components in application

Hi there, I'm currently experimenting with Laravel and experiencing an issue where the components I create are not showing up when I run the project. Strangely enough, the example component does appear but any changes I make do not reflect. I followe ...

Using the 'onended' audio event emitter in Angular 2 along with a local member of the Component

I'm looking for assistance on how to utilize audio.onended() in order to play the next song in a playlist. I can successfully add songs to the playlist and play them using the above method with an audioObject. However, when audio.onended triggers, I ...

Searching through the Symfony2 database with the help of Select2 and Ajax

Currently, my FAQ System is running smoothly. However, I am looking to enhance it by adding a search function using Select2. Here's what I have so far: Select2 AJAX Script <script> $("#searchall").select2({ ajax: { ...

Exploring the beauty of ASCII art on a webpage

Having trouble displaying ASCII art on my website using a JavaScript function, the output is not as expected... This is how it should appear: And here is the code I am trying to implement for this purpose: function log( text ) { $log = $('#log&ap ...

The CKEditor is having trouble properly opening code snippets

I have been using ckeditor 4.4 along with the code snippet plugin. Initially, when I create a document with a rich code snippet and save it, everything works perfectly fine. The source code for what is generated looks like this: <pre><code>&am ...

AngularJS $http.get request not working as expected

Hi there, I'm currently facing an issue with retrieving data from a webpage for use on my own website. I'm working with AngularJS and attempting to fetch data from . When checking my page in Chrome, I encountered the following error: Refere ...

Removing data from firestore/storage does not follow the expected pathway

I have created an image gallery for users using Firebase Storage and React, allowing them to upload and delete images. However, I am facing an issue where the deletion process is taking longer than expected. Expected flow: User clicks on the trashcan ico ...

Guide to receiving dynamic argument variables in jQuery using $.get

I am currently working on developing an Ajax function call. In this function, the argument q will be dynamically defined, and the $.get method will return either true or false based on the data received from the Ajax call. <a href="any.php" class ...

JavaScript element styling in a Partial view, experiencing issues with functionality

In the main view, the javascript element is working fine. However, in the partial view it seems to not be functioning even though it is correctly formatted. Any ideas on how to fix this issue? Check out this fiddle for reference: http://jsfiddle.net/bgrin ...

Guide on creating and dynamically appending an element to the DOM in VueJS triggered by a user clicking a button

I'm having an issue with my vue webapp. I want to make a square shape appear on the screen where a user clicks, but for some reason, my code isn't working as intended. Can someone help me figure out what's wrong? <template> <di ...

Adding a function into a node within PostgreSQL

Hi there, I'm currently following a tutorial and attempting to execute a simple insert query, however, I keep encountering a 404 error. I am using Postman to input values. function function insertUser(req, res, next){ req.body.users = parseInt(r ...

Front-end displaying empty data fields on my webpage

I've been struggling to understand why my data isn't mapping correctly on these two components. I have attempted two debugging methods to analyze my code and have observed the data object for both the navigation and footer. Unable to comprehend ...

Develop a search feature that automatically filters out special characters when searching through a

I am currently developing a Vue-Vuetify application with a PHP backend. I have a list of contacts that include first names, last names, and other details that are not relevant at the moment. My main query is how to search through this list while disregardi ...

Anticipate that the function will remain inactive when the screen width is less than 480 pixels

Implementing Functionality in Responsive Navigation <script> document.addEventListener('DOMContentLoaded', () => { let windowWidth = window.Width; let withinMobile = 480; let close = document.getElementById('close&ap ...

What is the most effective method to convert PHP data into JSON and present it in the jQuery success scenario?

In the realm of jQuery, I have this particular piece of code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> <script type="text/javascript" > $(function() { $("input[type ...

Master the art of string slicing in JavaScript with these simple steps

I am attempting to utilize the slice function to remove the first three characters of a string within a JSON object. $(document).ready(function() { $.ajaxSetup({ cache: false }); setInterval(function() { $.getJSON("IOCounter.html", functio ...

When creating a new instance of a class, I make sure to use the

I am facing an issue when trying to call a function from ClassA within my mainClass, and vice versa. I have attempted using .bind() and .call(), but it only works when I use .bind(this) or .call(this) on functions, not when I try to instantiate a new class ...

What is the best way to save an object with methods in a Vue application?

Looking for the best way to store complex objects with methods in Vue? Take this object as an example: const behavior = { onClick() { console.log('click') }, onDoubleClick() { console.log('double click'); }, on ...

Issue with displaying error message on span element during validation

Is there a way you can recommend for displaying the error message within element with id #genderError instead of after it? errorPlacement: function(error, element) { if (element.attr("name") == "myoptions" ) error.appendTo('#genderError'); ...

Adjust the size of images using jQuery to perfectly fit the container dimensions

I am currently working on a script to automatically resize images that are too large for the container: $('img').each(function(i){ var parent_width = parseInt($(this).parent().width()), image_width = parseInt($(this).width()); ...