Método de chamada Vue 3 de outro componente
// Register plugin to provide $externalMethods for components
app.use({
methods: {},
install(app) {
app.config.globalProperties.$externalMethods = {
set: (method, func) => this.methods[method] = func,
call: (method, ...args) => this.methods[method](...args)
}
}
});
app.component('button1', {
template: '#test-button',
methods: {
click(event, text) {
console.log(text || 'Button 1 default click')
}
},
mounted: function () {
console.log(this);
// Register global function
this.$externalMethods.set('button1/click()', this.click)
}
});
app.component('button2', {
template: '#test-button',
methods: {
click(event) {
// Call global function
this.$externalMethods.call('button1/click()', event, 'Hello from Button 2')
}
}
});
Disturbed Dove