I am finding the event naming conventions in Vue 3 to be quite perplex

In the parent component, there is a child component:

<upsetting-moment-step
    :this-step-number="1"
    :current-step-number="currentStepNumber"
    @showNextStep="showNextStep"
></upsetting-moment-step>

The parent component also includes this method:

methods: {
    showNextStep() {
        this.currentStepNumber++;
    }
},

The event is called from a button inside the child component:

<button type="button" class="btn btn-lg btn-primary" @click="showNextStep">Continue</button>

Here is the method in the child component:

methods: {
    showNextStep() {
        this.$emit('showNextStep');
    }
},

Everything works fine, but there's confusion when using @show-next-step instead of @showNextStep in the child component tag.

Despite what the documentation states, it should work with snake case and is recommended, however it doesn't seem to function properly.

An interesting discovery is that if changed to snake case, it works with this.$emit('show-next-step');. This leads to confusion as props are passed in snake case and used in camel case within the component.

Is there something missing?

Answer №1

Inside your custom component upsetting-moment-step, you have defined an event called @showNextStep. The "@" symbol signifies that it is an event. In order to trigger an action for this event, you must first emit it with the same name used in the component. Use this.$emit('showNextStep'); to emit the event. Once emitted, the code inside the function showNextStep will be executed.

It is recommended to follow naming conventions such as camelCase for JavaScript and kebab-case for tags and events.

Answer №2

The built-in event name conversion feature should function according to the documentation, as you have mentioned. However, it has come to our attention that there is a known issue (@vuejs/vue-next #2841) in versions 3.0.0 through 3.0.5.

The solution was implemented in version 3.0.6, but we recommend updating to the most recent release (3.2.7 as of today).

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

How can I create a script for a sliding/toggling menu?

Not sure if it's appropriate to ask, but I'm currently in search of a slide/toggle menu. Despite my efforts on Google, I haven't been able to find exactly what I need. As someone who is more skilled in HTML/CSS than jQuery or other scripting ...

What's causing Angular to not display my CSS properly?

I am encountering an issue with the angular2-seed application. It seems unable to render my css when I place it in the index.html. index.html <!DOCTYPE html> <html lang="en"> <head> <base href="<%= APP_BASE %>"> < ...

Tips for troubleshooting objects within an Angular template in an HTML file

When I'm creating a template, I embed some Angular code within my HTML elements: <button id="btnMainMenu" class="button button-icon fa fa-chevron-left header-icon" ng-if="(!CoursesVm.showcheckboxes || (CoursesVm.tabSelected == 'curren ...

Implementing a JavaScript confirmation based on an if-else statement

I need to display a confirmation dialog under certain conditions and then proceed based on the user's response of yes or no. I attempted the following approach. Here is the code in aspx: <script type="text/javascript> function ShowConfirmati ...

Tips on Creating a Display None Row with a Sliding Down Animation Using Javascript

I am working with a table that has some hidden rows which only appear when the "show" button is clicked. I want to know how I can make these hidden rows slide down with an effect. Here's the snippet of my code: function toggleRow(e){ ...

Unable to open modals in Bootstrap using jQuery script: modal not popping up

My attempt to create functionality for two buttons and two modals - reserve a campsite (id="reserveButton" should open id="reserveModal") and Log in (id="loginButton" should open id="loginModal") is not working. I ha ...

Vue: Ensuring one method finishes executing before triggering the next one

I've implemented two methods in my Vue instance; const app = new Vue({ el: '#app', data: { id: null }, methods: { getId: function() { return axios.get('url') .then(response => response.data) .then(i ...

Clever ways to refresh the current page before navigating to a new link using ajax and jQuery

Here's a different perspective <a href="{{$cart_items->contains('id',$productItem->id) ? route('IndexCart'): route('AddToCart')}}" class="item_add" id="{{$productItem->id}}"><p class="number item_price ...

What is the process to insert a record into a table by triggering an AJAX call upon clicking "save

I'm looking to dynamically update a table with data from a database using AJAX. Specifically, I want the table to reflect any new records added by the user without having to refresh the entire page. Below is my JavaScript code snippet for handling thi ...

Delegate All Events to the Document

In my current setup, I have over 350 events that look like: $(document).on('click','.removable-init',function(){}); I've noticed a performance issue where some click events are delayed by a fraction of a second. This is happening ...

Tips for styling Ajax.ActionLink elements with CSS

Hi there, I'm trying to style a navigation bar using CSS. I'm pulling the navigation bar values from a database using Ajax.ActionLink. I attempted to use JavaScript but encountered an error stating "jQuery is not defined", Here's the cod ...

Issues with merging styles in TinyMCE 4

I've exhausted all the current configuration options and I'm still unable to resolve this issue. My goal is to have the style tag appended to the selected element without generating an additional span. For example: <p>Hello World!</p> ...

Tinymce removes <html> tags from the output displayed in a textarea

I have created my own small CMS using Tinymce. When I insert plain text in pre tags, the code displays correctly on the website. However, when I update the editor, the HTML tags are removed. My Tinymce setup: <script type="text/javascript"> tinyMCE ...

Convert an array of JSON objects into a grid formatted time table using the

I am using Next.js 10 to create a timetable or schedule similar to the one below: bus stop time 1 time 2 time 3 {props[0].bus stop} {props[0].times[0]} {props[0].times[1]} {props[0].times[2]} ... {props[1].bus stop} {props[1].times[0]} {props[1] ...

Linking a Vue application within a PHP page using router hotlinking

Currently, I am in the process of developing a module for a CMS (Joomla) using VUE 3 with Router for the frontend. The prototype is functional and ready to be integrated into the CMS Module. The router is also working smoothly. However, when a user navigat ...

What is preventing the JQuery dialog from opening?

When I try to trigger a dialog box by pressing the enter key, it is not working as expected. Instead of opening the dialog, it just hides the text. Can someone help me understand what might be causing this issue? <!doctype html> <html lang="en" ...

Lately, I've been coming across mentions of "myApp.controllers" and "myApp.modules" in Angular JS. Can anyone explain the significance of these terms?

Recently, I've come across code that looks like this: angular.module('app.controllers') This pattern has appeared in a few tutorials I've read. However, the purpose of the .controllers within the module name is unclear to me. I'v ...

What is the reason for the omission of H1 tags from the table of contents list in NuxtJS's Content module?

Currently, I am facing an issue with importing a large amount of markdown content that heavily utilizes H1 (#) tags. While trying to create a table of contents (TOC) component, I noticed that the @Nuxt/Content package does not include H1 tags in the provid ...

What is the best way to switch between search results shown in an li using AngularJS?

Looking for a way to toggle a list that appears when a user searches in my app. I want the search results to hide when the search bar is closed. How can I achieve this? I think Angular might be the solution, but I'm stuck on how to implement it. I tri ...

React Data Filtering Techniques

I'm currently facing an issue with the if statement in my Action component. I'm struggling to figure out how to handle the case when an item is not found in the data from a JSON file. I have a Filtering function in a Context that I am using globa ...