Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change in vue composition api

I try to emit value change in new Vue Composition Api, like this

<template>
  <select
    @change="handleChange()"
  >
    <option value="text">Text</option>
    <option value="image">Image</option>
  </select>
</template>

<script lang="ts">
export default {
  name: "Select",
  setup(props, { emit }) {
    const handleChange = (event: any) => {
      emit("customChange", event.target.value);
    };
    return {
      handleChange,
    };
  },
};
<script/>

Return

Cannot read properties of undefined (reading ‘target’)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So i think is the are some error. Somebody see the error?

>Solution :

You are calling handleChange without arguments. Either do

@change="handleChange"

or

@change="handleChange($event)"

or

@change="e => handleChange(e)"

Any of them will pass the event as first parameter to your handler function.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading