There seems to be an issue with the VueJs + ElementUi Change method as it is

Just starting out with Vue and Element UI. I'm attempting to create a custom component using the ElementUI autocomplete/select feature.

The problem I am facing is that the @change method does not contain a event.target.value value.

When I try to access it, I receive the following error:

Error in v-on handler: "TypeError: Cannot read property 'value' of undefined"

Below is the code for my Vue component. It is being called using

<account-search v-model="newAccountForm.parent"></account-search>
from another component.

v-on:change.native="handleChange"
doesn't appear to be functioning at all.

<template>
    <div>
        <el-select :value="value" placeholder="Select" @change="handleChange">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
        </el-select>
    </div>
</template>

<script>
    export default {
        name: "accountSearch",
        props: {
            value: {
                type: String
            }
        },
        data(){
            return {
                options:[
                    {
                        value: 1,
                        label: "hello"
                    },
                    {
                        value : 2,
                        label : "ola"
                    }
                ],
                loading: false,

            }
        },
        mounted() {

        },
        methods: {
            handleChange: function (event) {
                console.log(event.target.value);
                // this.$emit('input', value);
            },

        }
    }
</script>

<style scoped>

</style>

Any assistance would be greatly appreciated.

Answer №1

The parameter passed to the handleChange function is actually value, not event

<template>
    <div>
        <el-select :value="value" placeholder="Select" @input="handleChange">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
        </el-select>
    </div>
</template>

<script>
    export default {
        name: "accountSearch",
        props: {
            value: {
                type: String
            }
        },
        data(){
            return {
                options:[
                    {
                        value: 1,
                        label: "hello"
                    },
                    {
                        value : 2,
                        label : "ola"
                    }
                ],
                loading: false,

            }
        },
        mounted() {

        },
        methods: {
            handleChange: function (value) {
                console.log(value);
                this.$emit('input', value);
            },

        }
    }
</script>

<style scoped>

</style>

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

Utilizing the navigator object in React Navigator and expo to enhance component functionality

My React Native application requires a redirection on a specific component. Within my main App.js component, I have the following code snippet: import React from "react"; import { Text } from "react-native"; import { createAppContainer } from "react-nav ...

Issue with React Native Hook where converting a function into a class variable results in 'undefined'

We are currently in the process of converting a react native function into a class so that we can implement state management compatible with Firebase's real-time database. It recently came to our attention that Hooks cannot be used within a class, so ...

Having trouble getting Video.js SWF to work on Internet Explorer?

I've been working with video.js and am having trouble getting it to function properly on Internet Explorer. I have added the swf file like this: videojs.options.flash.swf = "http://vjs.zencdn.net/4.2/video-js.swf " Here is the code for the video pla ...

What could possibly be causing my app to exhaust CPU resources on Mozilla Firefox?

I have created a unique game application for Facebook. Currently, the app is not optimized with AJAX technology, resulting in multiple server requests causing high CPU usage (specifically in Firefox) which slows down the overall performance of the app. Alt ...

Tips for simulating Axios requests in Jest

During my development process, I have implemented a function in my client/index.js file that utilizes axios to make HTTP requests import axios from "axios"; const createRequest = async (url, method) => { const response = await axios({ ...

Why is a dispatch call in React-Redux being executed before another?

My Pokedex is functioning properly, but I have encountered an issue with React-Redux Dev Tools: https://i.sstatic.net/F0Ifh.png The function "getPokemonsInfo" is being called before "getPokemonsUrls", however, "getPokemonsInfo" should only be triggered w ...

Implementing the adding functionality within an ejs file

I'm currently working on a project that involves fetching data from an API using a simple JavaScript file upon clicking a button. Initially, everything was functioning properly when both the HTML file and JS file were in the same folder, and I could a ...

The functionality of linear mode seems to be malfunctioning when using separate components in the mat-horizontal-stepper

In an effort to break down the components of each step in mat-horizontal-stepper, I have included the following HTML code. <mat-horizontal-stepper [linear]="true" #stepper> <mat-step [stepControl]="selectAdvType"> <ng-template matStep ...

What are the best practices for iterating through asynchronous generator functions?

Suppose we have an asynchronous generator: exports.asyncGen = async function* (items) { for (const item of items) { const result = await someAsyncFunc(item) yield result; } } Can we apply mapping to this generator? In essence, I am attempting ...

Is it possible to apply capitalization or convert the value of props to uppercase in React?

Despite attempting the toUpperCase method, I am unable to capitalize my props value. Here's the code I have: export default function Navbar(props) { return ( <> <div> <nav class="navbar navbar-expand-lg bg-b ...

Issue with PeerJs Localhost Setup

Implementing the zoom clone with WebRTC using peerjs, I am facing an issue where myPeer.on("call", (call) => { is not getting called. This code works fine for others on localhost who followed the tutorial on the zoom clone. I am unsure of what ...

In Angular JS pagination, the previous filter value is stored in $LocalStorage for future reference

One view displays all order records in a tabular format with 10 records per page. A filter is set to show only paid orders, which pops up filtered data when selected. An issue arises when closing the pop-up window and navigating to the next page of the t ...

Guide on importing table information into an array using jQuery

I am facing an issue where I want to extract values from a dynamically generated table and then send those values in an AJAX call. The problem is that even though I am able to increase the number of rows in the table dynamically, when I try to capture the ...

The view named 'HelloWorld' could not be found within the servlet named 'dispatcherServlet'

I have recently started learning Spring Boot. My goal is to display an HTML page, but unfortunately I am facing some issues. When I change HelloWorld.html to HelloWorld.ftl, I am able to display the FTL page. However, the vue.js file is not being resolve ...

Using JQuery and Javascript to retrieve information from one drop down list based on the selection made in another drop down

I'm currently working on a project that involves 2 drop-down menus. The first menu allows you to select a general model, while the second menu displays specific models based on your selection. http://jsfiddle.net/QskM9/ Here's an example of how ...

Efficiently perform complex nested grouping using the powerful array

Hi, I'm currently facing difficulties while attempting to utilize the array.reduce() function in order to achieve correct grouping for a specific scenario: Here is my original array: { { descriptionFunction: "Change", processDate: "201 ...

Guide to creating a hierarchical navigation system with HTML

Is there a way to create a menu tree using just HTML and some scripting, without downloading additional software? I tried searching on Google but all the results require downloads. Can anyone provide guidance or help with this task? Thank you in advance. ...

Despite successful installation, node remains elusive on Ubuntu VPS

After installing node using NVM with version 0.25.0, I specifically installed node version 0.10.32. However, upon running node -v, the following error is displayed: -bash: /root/.nvm/v0.10.32/bin/node: No such file or directory Similarly, when executing ...

Maximizing efficiency in JavaScript by utilizing jQuery function chaining with deferred, the .done() function

I am working on retrieving data from multiple functions and want to chain them together so that the final function is only executed when all the data has been successfully loaded. My issue arises when trying to use the .done() method, as it calls the func ...

Filtering an Array of Objects on the Fly in Vue.js

I'm currently working on a Vue.js app where I need to dynamically apply filter values to an Array of objects based on their field values. Each object in the Array has various fields that I want to filter by. The challenge is that each field can have m ...