Vue draggable component

I'm currently facing an issue while trying to integrate the Vue Draggable Component into my existing component. Everything works perfectly fine in my component without the draggable feature, but as soon as I add it, the entire content becomes blank. I suspect that this might be due to a configuration problem. Any guidance or help on this matter would be highly appreciated.

The latest error message I encountered is as follows:

Invalid vnode type when creating vnode: undefined

<template>
<div :class="['image-select']">
  <draggable v-model="images">
    <div v-for="image in images"
         :class="['image-select-image']"
         :key="image.id">
        <input type="hidden"
             :name="fieldName()"
             :value="image.id">
      <img :src="imageUrl(image,size)" :alt="image.alt">
    </div>
  </draggable>
</div>
</template>

<script setup>
import {onBeforeMount, ref} from 'vue';
import api from "../modules/api";
import {draggable} from "vuedraggable";

const props = defineProps({
    size: {
        type: String,
        default: 'sm'
    },
    name: {
        type: String,
        default: 'images'
    },
    selectedValues: {
        type: Object,
        default: null
    }
});

const images = ref([]);

onBeforeMount(async () => {
    await Promise.all([
        setImages()
    ]);
});

function fieldName(){
    return props.name + '[images][]';
}

function imageUrl(image, size){
    return image.src.replace(/\/[a-zA-Z0-9_\.-]+(\.[a-zA-Z]+)$/,'/'+size+'$1');
}

function setImages(){
 // load images from ids in selectedValues
}

</script>

Answer №1

As outlined in the official documentation, it is recommended to import the module without using curly braces {}

import draggable from 'vuedraggable';

Due to how the vuedraggable component is structured for export, utilizing curly braces in the import statement will result in an error.

For a demonstration, refer to this codesandbox example

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

Having trouble submitting a date input form generated with vuejs on Safari browser

I am a huge fan of Vuejs and it's my go-to at work. The other day, I came across a rather perplexing scenario. If you have any insights into this, please do share. Here is the code in question: <script setup lang="ts"> import { ref ...

The installation of webtorrent-hybrid failed due to the error message "node-pre-gyp: command not found"

I'm currently encountering an issue while attempting to install webtorrent-hybrid for developing an electron p2p application. Vue UI is the framework I am using to handle front-end development, and I have successfully created a new project utilizing v ...

Is it possible to use an external template and style in a Vue component?

Is it feasible to use a Vue component that has its template stored in an external file (.html)? Is there a similar approach for the style that is stored in a .scss file? This strategy could streamline our development process, allowing front-end HTML devel ...

Distinguish between datalist selection and text input in BootstrapVue Autocomplete

When looking at the code snippet provided below, I'm trying to figure out the appropriate event/method to determine whether the value entered in the input field was manually typed or selected from the <datalist>. SAMPLE CODE: <div> &l ...

Issue (@websanova/vue-auth): http plugin has not been properly configured in drivers/http/axios.js

I've been working on integrating vue-auth into my laravel-vue application, but I'm encountering some console errors: Error (@websanova/vue-auth): drivers/http/axios.js: http plugin has not been set. Uncaught TypeError: this.plugins.http is u ...

Error message: Unable to load image from local source in Vue application

I am currently working on creating a simple dice roll game in VueJs. However, I encountered an issue with using the dice images as it keeps giving me a 404 error. When I attempted to use require(), it stated that the function was not defined. After some t ...

Ways to incorporate sass:math into your vue.config.js file

While using vue-cli with Vue 2.6 and sass 1.49, I encountered errors in the console related to simple division calculations: Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0. I attempted to ...

Dealing with callback errors: error handling is anticipated

In my Vue web application, I have enabled ESLint and encountered an issue with the following code: myApi.get('products/12').then((prodResponse) => { state.commit('ADD_PRODUCT', {product: prodResponse.data}) }, error => { cons ...

Showing a Bootstrap.vue b-table containing nested arrays within arrays

I am facing an issue while trying to display data in a b-table. Normally, it works well with most data sets. However, when I encounter another array nested within the referenced array, the rendering is not done properly. While working on this problem, I ...

Unable to attach child component to reference

I am currently facing an issue with VuePaginator. Despite following the documentation, I am unable to mount it to my Vue app's $refs properties. The pagination feature is working correctly, but I cannot trigger the fetchData() function from my Vue cod ...

Utilizing Vue and Websockets for seamless communication: Managing the exchange of messages between users

In an attempt to create a messaging system that shows alerts of messages to different users, I have implemented Vue Socket Io from https://www.npmjs.com/package/vue-socket.io. However, the issue lies in the fact that the alerts are not being triggered as e ...

Encountered a SyntaxError in vue + webpack regarding an invalid range in character class

I am currently using webpack 4.29.3 and vue.js 2.6.3 to create a simple hello world project. I expected the index.html file to render correctly, but I encountered an error: SyntaxError: invalid range in character class. This error is confusing because I&ap ...

Error: Attempting to access the `isPaused` property of a null object is not possible

For my Vue front-end app, I'm attempting to integrate wavesurfer.js. However, upon receiving the audio file link from the backend, I encounter the following error: wavesurfer.js?8896:5179 Uncaught (in promise) TypeError: Cannot read property 'isP ...

The Swiper library is incompatible with the "vue" version "^2.6.11" and cannot be used together

I've been attempting to incorporate Swiper with "vue": "^2.6.11", however I keep encountering runtime errors. Despite following the instructions on , and modifying the imports as advised: // Import Swiper Vue.js components import { ...

Exploring Nuxt.js: A guide to server-side caching of axios calls for universal client access

I am currently working on a project using Vue and Nuxt.js. I am wondering if there is a way to cache an axios web service call for all clients. Specifically, I need to retrieve currency reference data and it seems inefficient for every client to make this ...

Vue js: Automatically assign alternate text to images that are not found

Currently, I am in the process of developing a website that features a variety of products, each with its own unique image. For binding the image URL to the source attribute, I use the following code snippet: <img :src="product.ImageUrl"/> In case ...

Obtain model value that has been stylized using Vue.js

In my Vue.js application, there is a table that lists both a URL and an Id. The URL is user-defined, so I implemented an input component with a text input field to display the URL value and pass the Id as a parameter. The v-model of this component is an ar ...

Is there a way for me to insert a variable into the src attribute of my img tag like this: `<img alt="Avatar" src=`https://graph.facebook.com/${snAvatarSnuid}/picture`>`

I need assistance with passing a variable called snAvatarSnuid within the img src tag, specifically after facebook.com/ and before /picture as shown below: <img alt="Avatar" src=`https://graph.facebook.com/${snAvatarSnuid}/picture`> Note: 1) The ht ...

Avoid having Vue CLI delete all files in the dist folder

As I work on my Vue project, I am facing a challenge in syncing the dist folder with Git. Previously, this process ran smoothly when using webpack. However, after transitioning to @vue/cli and creating my project with vue create myProject instead of vue in ...

(vue router) What is the most efficient way to avoid code repetition when setting up two routes that share a nearly identical view?

My NewArticleView vue component is linked to the URL path /articles/new. Here's how it's set up: const routes = [ ... { path: '/articles/new', name: 'New Article', component: NewArticleView ...