How to use the method of the current page to another page through $emit and $on?

now you want the method of the current page to be used on another page. You can"t see the $emit and $on method transfer calls on the official website

.

clipboard.png

1. Create a new file for event.js

import Vue from "vue"
export let Event = new Vue()
export let KEY = "search"

2. In the current page reference, the full method is defined in methods. I don"t know how to send this method, and then how to receive

on other pages.
import { Event, KEY } from "../../utils/event.js";
Event.$emit(KEY, this.full());

3. For other pages, I don"t know how to receive the method

    Event.$on(KEY, function() {});
Mar.22,2021

take the project just initialized by vue-cli. In the HelloWorld component, we actively trigger $emit,

app.vuemounted$on

. When you click, it will trigger the console to output the value received by $on

.

but if you say that it is sent on the current page and received on other pages, if that means, in component a, when the route jumps to component b to receive, why not use routing parameters to solve it? if this kind of event is sent, when you send it, component b has not been created yet, how can it receive it

Menu