Having trouble uploading images in Vue.js due to a component issue affecting events

Hey there, I'm currently facing an issue while trying to upload images using this plugin. It seems that my uploadImageSuccess event is not triggering as expected. Apologies if I made a mistake, I'm still new to Vue.js.

Here is the code snippet I'm working with:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>vue-upload-multiple-image</title>
    </head>
    <body>
        <div id="el">
            <div id="my-strictly-unique-vue-upload-multiple-image" style="display: flex; justify-content: center;">
                <vue-upload-multiple-image
                    @upload-success="uploadImageSuccess"
                    @before-remove="beforeRemove"
                    @edit-image="editImage"
                    @data-change="dataChange"
                    :data-images="images"
                    ></vue-upload-multiple-image>
            </div>
        </div>


        <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
        <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="daacafbff7afaab6b5bbbef7b7afb6aeb3aab6bff7b3b7bbbdbf9aebf4eaf4e8">[email protected]</a>/dist/vue-upload-multiple-image.js"></script>
        <script type="text/javascript">
            var vm = new Vue({
                el: '#el',
                data() {
                    return {
                        images: []
                    }
                },
                components: {
                    VueUploadMultipleImage
                },
                methods: {
                    uploadImageSuccess(formData, index, fileList) {
                        alert('dd');
                        console.log('data', formData, index, fileList)
                        // Upload image api
                        // axios.post('http://your-url-upload', { data: formData }).then(response => {
                        //   console.log(response)
                        // })
                    },
                    beforeRemove(index, done, fileList) {
                        console.log('index', index, fileList)
                        var r = confirm("remove image")
                        if (r == true) {
                            done()
                        } else {
                        }
                    },
                    editImage(formData, index, fileList) {
                        console.log('edit data', formData, index, fileList)
                    },
                    dataChange(data) {
                        console.log(data)
                    }
                }
            });
        </script>
    </body>
</html>

If anyone can provide some guidance on this it would be greatly appreciated. The error message I'm seeing reads:

ReferenceError: VueUploadMultipleImage is not defined

Answer №1

When utilizing a CDN to import the plugin (e.g.

https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c2a293971292c30333d387131293028352c30397135313d3b391c6d726c726e">[email protected]</a>/dist/vue-upload-multiple-image.js
), it will be readily available globally in your DOM. Therefore, there is no need to manually mount VueUploadMultipleImage like this:

 components: {
      VueUploadMultipleImage
 }, 

By omitting that snippet above, you can avoid encountering a ReferenceError.


Just to cover all bases, remember that the mentioned snippet is necessary only if you are using the plugin via NPM. In such case, start by importing the plugin:

import VueUploadMultipleImage from 'vue-upload-multiple-image'

Then proceed to mount it as follows:

  components: {
    VueUploadMultipleImage,
  },

I hope this information proves helpful!

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

Exploring table iteration in Angular 7

I am looking to create a table with one property per cell, but I want each row to contain 4 cells before moving on to the next row... This is what I want: <table> <tr> <td> <mat-checkbox>1</mat-checkbox& ...

Struggling to navigate the world of Nuxtjs and graphql

Having trouble with v-for and iterating through nested objects in Nuxtjs, Strapi, and GraphQL Received this object from GraphQL: "fotografies": { "data": [ { "id": "1", "attributes&qu ...

The jquery accordion title width does not align with the content width when an icon is included

Is there a way to adjust the widths of the heading and div elements after adding edit and delete icons to match the standard accordion style? Thanks <div id="accordion"> <h3><a href="javascript:;"> ...

Find the time interval between two timestamps and output the difference in UNIX timestamp format

Is there a way to determine the time difference between two dateTime values? One date is provided by the user, while the other is the current time: User-submitted time - current time = difference in Unix timestamp The format for the user-submitted time i ...

Tips on refreshing the D3 SVG element following updates to the dataset state in a React application

Hey everyone, I'm currently experimenting with D3.js and React in an attempt to build a dynamic dancing bargraph. Can anyone provide guidance on how to reload the D3 svg after updating the dataset state within REACT? Feel free to check out my codepen ...

Is it necessary to use asynchronous actions in Node.js only when developing server applications?

In the Node.js application I'm developing, there is a piece of code similar to this within an async function: await a(param1); await b(param2); await c(param3); await d(param4); From my understanding, this setup works well for a server-based app. Fo ...

Using TypeScript to Infer Types in a Wrapper Function

When it comes to functions related to database operations, I have a handy utility/wrapper function that handles specific tasks. It takes a function fn of type Promise<PromiseReturnType<GENERIC>>, performs some preliminary actions (such as check ...

How can the total price for a shopping cart be computed in React/Redux?

After extensive searches on Google and SO, I'm still coming up empty-handed when it comes to calculating the total price of items in a cart. Many tutorials stop at basic cart functionalities like "Add item to cart" or "increase/decrease quantity", but ...

Personalizing the label of a select input using materialui

Working on customizing a select element using the "styled" method: const StyledSelect = styled(Select)` height: 2rem; color: #fff; border-color: #fff; & .${selectClasses.icon} { color: #fff; } & .${outlinedInputClasses.notchedOutl ...

Revamp webpage content and links without refreshing the page, similar to the navigation menu on Facebook

My website consists of two HTML pages, specifically contact.html and index.html. Additionally, there is a menu-sidebar and a content div integrated into the web design. There are two main objectives I am looking to achieve: 1. The ability to swap between ...

Passing a query variable to an input field through a PHP function

I have developed an autocomplete PHP function that connects to a MySQL database to fetch data based on user input: The PHP file is named search.php and contains the following code: if ( !isset($_REQUEST['term']) ) exit; $dblink = mysql_con ...

s3 is having trouble uploading the file and is returning an error stating SignatureDoesNotMatch

I'm experiencing an issue while attempting to upload images to my s3 bucket in aws. The error message SignatureDoesNotMatch keeps appearing. Below is the code I am using to upload the file/image: FrontEnd const file = e.target.files[0]; const fileP ...

How can you display a border around a <td> element in an HTML table only when it contains data, using jQuery or JavaScript?

My HTML table consists of the following structure: <table class="table table-bordered"> <thead> <tr> <th>Tag</th> <th>Time Code</th> </tr> </thea ...

Javascript troubleshooting: Confusion with Radiobuttons and Checkboxes 'checked' status

My Javascript code utilizes JQuery to generate quizzes with free text, radio buttons (single choice), and check boxes (multiple choice) questions. These quizzes are created using a web interface styled with Zurb - Foundation and serialized in JSON format. ...

Creating a realistic typewriter effect by incorporating Code Block as the input

I am looking to add a special touch to my website by showcasing a code segment with the Typewriter effect. I want this code block not only displayed but also "typed" out when the page loads. Unfortunately, I have been unable to find a suitable solution s ...

What is the best way to utilize a variable across all functions and conditions within an asynchronous function in Node.js?

I need to access the values of k and error both inside and outside a function. Initially, I set k to 0 and error to an empty string, but unexpectedly, the console prints out "executed". var k = 0; var error = ""; const { teamname, event_name, inputcou ...

Supabase is encountering an issue: 'TypeError: fetch failed'

I'm currently developing a to-do list application using Supabase and NextJS-13. However, when I tried fetching the lists from Supabase, the server returned an error. Error Image The List table on Supabase consists of three columns: id created_ ...

Safari compatible JavaScript needed for enforcing required fields in HTML5

I have been using the following script to adjust the HTML5 required attribute of my input elements. However, I am now looking for a way to tweak this script so that it can also function properly in Safari browsers, where support for this attribute may be l ...

Having trouble adding space between paragraphs inside a div element while trying to retrieve its content using jQuery

Issue Description: Currently, I am utilizing the jQuery syntax below to count words: var value = $('#displayContent').text(); Before counting the words, I aim to employ a RegExp in value that concatenates the last word of each sentence with th ...

Retrieving a particular value from an array received through Ajax in JavaScript

Ajax functionality $("#panchayat").change(function(){ var param = {'panchayat_id':$(this).val()}; alert (param['panchayat_id']); $.ajax({ type : 'POST', url : '<?php echo base_url();?>index.php/parent_taluk' ...