The Vue event was triggered, however there was no response

My current project consists of a Typescript + Vue application with one parent object and one component, which is the pager:

//pager.ts
@Component({
    name: "pager",
    template: require("text!./pager.html")
})
export default class Pager extends Vue {
    onClick(pageIndex: number) : void{
        this.$emit("pageClick", pageIndex);
    }
}

<!-- pager.html -->
<div id="pager" class="text-center" xmlns:v-on="http://www.w3.org/1999/xhtml">
    <a v-on:click="onClick(1)">
        1
    </a>
</div>

The main Vue object along with its corresponding html file are as follows:

// main.ts
this.vue = new Vue( {
    el: "#log-container",
    components:{
        pager: Pager
    },
    methods: {
        loadFromServer(pageIndex: number) : void
        {
            // do thing
        }
    },
    created(){
        // it workes
        this.loadFromServer(1);
    }
});

<!-- main.html -->
<div id="log-container">
    <pager v-on:page-click="loadFromServer">
    </pager>
</div>

The issue I am facing is that although the event was emitted successfully, it was not received by the main Vue object and the loadFromServer method was not called.

In addition:

  • This method is also called inside created and functions properly
  • If I change v-on:page-click="loadFromServer" to v-on:page-click="somethingElse", I will receive a Vue error stating that the method somethingElse does not exist. This indicates that Vue is parsing my code correctly.

Despite all these observations, the loadFromServer function remains uncalled.

Answer №1

Special thanks to @Bert for sharing the correct approach of using kebab-case when emitting events.

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

The type 'LoadableComponent<unknown>' cannot be assigned to type 'ReactNode'

Currently in the process of migrating from react-router-dom v5 to v6. // Original code using react-router-dom v5 <Route exact path="/" component={router.Home} /> // Updated code for react-router-dom v6 <Route path="/*" element ...

Struggling to solve a never-ending loop problem in a messaging application

I am currently in the process of developing a chat application. During the initialization of the chat page, I am checking for messages and storing them in an array. ngOnInit() { this.messageService.getMessages().doc(`${this.sortItineraries[0] + ...

What is the best way to delay an observable from triggering the next event?

In my Angular project, I am implementing RxJs with two subjects. s1.next() s1.subscribe(() => { // perform some operation and then trigger the event for s2 s2.next() }); s2.subscribe(() => { // perform some operat ...

Upon deployment, Angular encounters issues with routing to lazy loaded modules

I recently completed development on a new Angular application that utilizes lazy loading for improved performance. During local testing using ng serve (or ng serve --prod to mimic production mode), the app compiled without errors and functioned properly. ...

Vue: Duplicating a div element with unique input fields upon clicking

I have successfully set up a page where I can dynamically add a div/row of inputs by clicking the link. This feature works smoothly and adds the same div below the current one with all the proper inputs. Additionally, one of the inputs is designed as an a ...

Is there a way for me to retrieve the bodyHeight attribute of ag-grid using public variables or data?

Working on a project using ag-grid community react. The main feature is a scrollable section filled with data, which can range from one piece to millions of pieces. I'm also incorporating a footer component for the grid that needs to adjust its height ...

The value of the filename property cannot be determined as it is undefined

Hey everyone, I'm currently working on a project using nestjs and reactjs. I encountered an error when trying to add a document that reads: "Cannot read properties of undefined (reading 'filename') in multer.config.ts" import { diskStorag ...

TypeScript: creating an interface property that relies on the value of another

Is it feasible to have an interface property that relies on another? For instance, consider the following: const object = { foo: 'hello', bar: { hello: '123', }, } I wish to ensure that the key in bar corresponds to the value of f ...

The property 'item' is not found within the specified type 'IntrinsicAttributes & RefAttributes<Component<{}, any, any>>'. Error code: 2322

"react": "^16.12.0", "typescript": "^4.0.3", "next": "^9.4.4" The error being raised by typescript is related to the <Item item={item} key={item.id} urlReferer={urlReferer} /> prop used ...

Package.json file is not included in Typescript

Each time I execute tsc, it converts the files to JS format successfully, except for package.json. I want this file included in my output directory. Currently, my tsconfig.json looks like this: { "exclude": ["node_modules"], "compilerOptions": { " ...

Using React with Typescript: Anticipating child component with particular props

I'm currently developing a component that necessitates the use of two specific child components. These two components are exported using dot notations from the main component and have defaultProps for identification within the main component: export ...

Go all the way down to see the latest messages

I have developed a messaging system using Vue. The latest messages are displayed from bottom to top. I want to automatically scroll to the end of a conversation when it is clicked and all the messages have been loaded via axios. Conversation Messages Comp ...

Setting the desired configuration for launching an Aurelia application

After creating a new Aurelia Typescript application using the au new command from the Aurelia CLI, I noticed that there is a config directory at the root of the project. Inside this directory, there are two files: environment.json and environment.productio ...

What is the best way to add bootstrap.min.js into a Vue JS project?

My Vue JS application's Bootstrap nav-bar is not functioning properly on mobile devices. Despite installing the Bootstrap, JQuery, and popper node modules, I am encountering an error message that reads "Module Not Found. Can't resolve 'node_ ...

Is the TypeScript compiler neglecting the tsconfig.json file?

I am new to TypeScript and currently exploring how to set it up in WebStorm. One of the first steps I took was creating a tsconfig.json file in the main directory of my project and updating the built-in TypeScript compiler to version 1.6.2. However, despit ...

Embedding a TypeScript React component within another one

Currently, I'm facing an issue with nesting a TypeScript React component within another one, as it's causing type errors. The problem seems to be that all props need to be added to the parent interface? Is there a way to handle this situation wi ...

Exploring in vuejs connected to laravel backend api

Currently, I am utilizing Laravel 5.6 as the backend API and Vue.js for the frontend single-page application. Additionally, I have incorporated the https://github.com/nicolaslopezj/searchable package for search functionality, which has proven successful in ...

What could be causing the issue when attempting to run "npm run serve"?

Can anyone help me understand this error message and suggest a possible solution? Failed to compile. ./src/main.js Module build failed (from ./node_modules/eslint-loader/index.js): Error: No ESLint configuration found. at Config.getLocalConfigHierar ...

The build error TS1036 is thrown when a function with a return statement is moved to index.d.ts, even though it worked perfectly in a standard TS file

In my project using Node v14.x and StencilJS (React) v2.3.x, I encountered an issue with a test-helper file containing a function that converts string-arrays to number-arrays: export function parseNumericStringOrStringArrayToIntegers(value: string | (strin ...

VueCropper fails to load properly

After attempting to incorporate VueCropper into my Component, I encountered a few issues: The sourceImg is displayed, but there is no cropbox or preview. When I examine console.log(this.$refs) and console.log(this.$refs.cropper), the results seem contrad ...