Utilizing Vue3's draggable component to seamlessly incorporate items

My current project involves the use of the vue draggable package, and below you will find the complete component:

<template>
  <div>
      <button class="btn btn-secondary button" @click="add">Add</button>
      <draggable tag="ul" :list="list" class="list-group" handle=".handle">
        <li
            class="list-group-item"
            v-for="(element, idx) in list"
            :key="element.name"
        >
          <i class="fa fa-align-justify handle"></i>

          <span class="text">{{ element.name }} </span>

          <input type="text" class="form-control" v-model="element.text" />

          <i class="fa fa-times close" @click="removeAt(idx)"></i>
        </li>
      </draggable>

    <rawDisplayer class="col-3" :value="list" title="List" />
  </div>
</template>

<script>
import { VueDraggableNext } from 'vue-draggable-next';
let id = 50;
export default {
  name: "handle",
  display: "Handle",
  instruction: "Drag using the handle icon",
  order: 5,
  components: {
    draggable: VueDraggableNext,
  },
  data() {
    return {
      list: [
        { name: "Navigation", text: "", id: 0 },
        { name: "Contact", text: "", id: 1 },
        { name: "Products", text: "", id: 2 },
      ],
      dragging: false
    };
  },
  computed: {
    draggingInfo() {
      return this.dragging ? "under drag" : "";
    }
  },
  methods: {
    removeAt(idx) {
      this.list.splice(idx, 1);
    },
    add() {
      id++;
      this.list.push({ name: "Navigation 2 " + id, id, text: "" });
    }
  }
};
</script>
<style scoped>
  .button {
    margin-top: 35px;
  }
  .handle {
    float: left;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .close {
    float: right;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  input {
    display: inline-block;
    width: 50%;
  }
  .text {
    margin: 20px;
  }
</style>

I am utilizing vue3 which is why I have implemented the Vue Draggable Next package to prevent the error message "an draggable element must have an item slot". However, after adding an item, it triggers an automatic reload. I am uncertain where the issue lies and would like to rectify it to avoid this behavior.

Answer №1

Consider using the suggested template wrapper:

  <template #widget="{ item }">
    <div class="container">
      <p>{{ item.title }}</p>

      <span class="description">{{ item.description }}</span>

      <input type="text" v-model="item.data" />

      <button @click="removeItem(index)">Remove</button>
    </div>
  </template>

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

Navigating AngularJS with multiple external files and folders

Recently dove into Angular and hit a roadblock with routing. I followed the setup instructions, but for some reason it's not functioning as expected. index.html: <!DOCTYPE html> <html lang="en> <head> <meta charset="utf-8> ...

Require assistance in generating three replicas of an object rather than references as it currently operates

I am encountering an issue with my code where I seem to be creating 4 references to the same object instead of 4 unique objects. When I modify a value in groupDataArrays, the same value gets updated in groupDataArraysOfficial, groupDataArraysValid, and gro ...

Autofill Text Input with React Material-UI

For my current project, I am utilizing Material UI and React. Each TextField in the project has a button next to it, and when the button is clicked, I want it to retrieve the value of its corresponding TextField and set that value as the input for another ...

Issue with Observable binding, not receiving all child property values in View

When viewing my knockout bound view, I noticed that not all values are being displayed. Here is the script file I am using: var ViewModel = function () { var self = this; self.games = ko.observableArray(); self.error = ko.observable(); se ...

What is the solution for fixing the Typescript error in formik onSubmit?

I encountered an error while using the onSubmit prop of Formik: The type '(values: { email: string; password: string; }) => { type: string; payload: { email: string | null; password: string | null; }; }' is not compatible with the type '(( ...

When using React, the event.target method may unexpectedly return the innerText of a previously clicked element instead of the intended element that was

I have implemented a drop-down menu that triggers an event handler to return the selected option when it is clicked. Upon clicking on an option, I retrieve the inner text of that option using the event. The code snippet looks like this: event.target.inner ...

How can I maintain the consistent speed of the Javascript timer even when the .deck is clicked?

Currently, I'm working on creating a memory card game. In this game, the deck of cards is represented by the class .deck. Strangely enough, every time I click on a card, the timer starts to speed up instead of keeping a consistent pace. How can I tack ...

Reorganizing divisions with Dojo

I came across a thread on StackOverflow that was similar to what I'm looking for. jQuery removing an element and renumbering remaining elements However, since we don't use jQuery but instead rely on Dojo, I'm unsure how to achieve the same ...

A guide to organizing the alphabet into groups and displaying them in a Vue template

In my Vue.js data, the structure looks like this: new Vue({ el: "#app", data() { return { alpha: [{ artist: "Aa" }, { artist: "Az" }, { artist: "Ab" }, { artist ...

Utilize the Tab feature effectively in Impress.Js

Currently, I have disabled the Tab key in Impress.js so that it only moves to the next slide. However, when I try to focus on links and delete this code to let it behave normally, Impress.js crashes. Has anyone found a workaround for this issue? Appreciat ...

What is the best way to upload a file and data simultaneously using Axios?

I'm currently facing an issue with posting data in a Vue application. Specifically, I am struggling with incorporating an image file input within the form. While most resources suggest sending the file separately or alongside other files,[1][2] What ...

Index is bound to data using a specific syntax for data binding

Having trouble with a syntax issue that is likely simple. I am attempting to replace the '1' in 'play1' with the v-for index. <tr v-for="index in 5"> <td>{{player1.round1['play' + index]}}</td> <td> ...

Customizing font size in React with Material UI: A comprehensive guide on adjusting the font size of the Select component

I'm currently working on a web application that utilizes React along with Material UI. My goal is to adjust the font size of the Select component. I've attempted to achieve this by utilizing the MenuProps property, as shown in the following code ...

The TypeScript compiler generates a blank JavaScript file within the WebStorm IDE

My introduction to TypeScript was an interesting experience. I decided to convert a simple JavaScript application, consisting of two files, into TypeScript. The first file, accounts.ts, contains the main code, while the second one, fiat.ts, is a support f ...

Tips for including parameters in an array of values when using getStaticPaths

I'm trying to retrieve the slug value that corresponds with each number in the getStaticPaths for my page structure: /read/[slug]/[number]. The code I have is as follows: export async function getStaticPaths() { const slugs = await client.fetch( ...

How is UI Router Extras causing unexpected errors in my unit tests?

QUESTION: - I am facing failures in my tests after installing ui-router-extras. How can I resolve this issue? - Is there a way to use ui-router-extras without causing test failures? If you want to quickly install this, use yeoman along with angular-full ...

What is the best way to ensure that an iframe adjusts its height to fit the content within a tabbed container?

Is there a way to dynamically set the height of an iframe to match the content inside it when clicking on a tabbed plane? Initially, I used a fixed height of 1000px. How can this be achieved? <div class="container-fluid text-center"> <div ...

What is it about that that ticks off so many different boxes?

Hey there! I've been working on creating checkboxes within next js that iterate through each filter and its options. Fortunately, I managed to get it up and running smoothly. However, I'm encountering an issue where checking one option in a speci ...

Eliminating event listeners in Nuxt/Vue application

In my current project on Nuxtjs 2.13, I have a question regarding the removal of event listeners. Is it necessary and how should I go about doing it? I'm not referring to traditional JavaScript methods like addEventListener and removeEventListener. I ...

Windows location does not change after an XMLHttpRequest is made

Here is my code that uses XMLHttpRequest: function SignUp() { signUpConnection = new XMLHttpRequest(); signUpConnection.onreadystatechange = processRegistration; signUpConnection.open('GET', 'index.php?registrarse=&username= ...