This is taking more than usual to get the $emit function to work, Im using vue js with laravel 5.6 as my backend framework.
This is seriously making me worry on how to fix the issue because NOTHING SO FAR HAS FIXED IT, so i will put all the code that i have maybe somebody can suggest a fix.
i have a tools and theme manager component on my main page blade file
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}" dir="ltr">
<head>
<title>{{ config('app.name') }}</title>
<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<meta name="csrf-token" content="{{ csrf_token() }}">
<link href="{{ mix('/css/designer.css') }}" rel="stylesheet">
<link href="{{ asset('/css/fontawesome5/css/all.min.css') }}" rel="stylesheet">
<body class="bg-blue-lightest font-light leading-normal">
<div id="designer">
@include('admin.designer.ui.vd-navbar')
@yield('content')
<theme-manager @theme-requested="showThemeManager"></theme-manager>
<tools></tools>
</div>
<script type="text/javascript" src="{{ mix('/js/designer.js') }}"></script>
</body>
</html>
This is my main js file -> designer.js
require('./bootstrap');
window.Vue = require('vue');
window.swal = require('sweetalert2')
import Tooltip from 'tooltip.js';
Vue.component('theme-manager', require('./components/ThemeManager.vue'));
Vue.component('tools', require('./components/Tools.vue'));
const app = new Vue({
el: '#designer',
methods: {
showThemeManager : function(){
alert();
},
}
});
from tools component i have a button that when clicked it $emits a function to show theme manager component on the page like this
<template>
<div class="fixed pin-b pin-r p-5 justify-center">
<a href="javascript:void(0)" class="text-white" @click="openThemeManager">
</a>
</div>
</template>
<script>
export default {
methods: {
openThemeManager: function(){
this.$emit('theme-requested');
}
}
}
</script>
The alert function on the main js file is not getting triggered as expected? so basically its not getting passed from child to parent, not sure what is going on, Just to make it simple i will explain what i did in words
i have 2 components tools and theme-manager component on my app, from tools component i have a button that should show the other component (theme-manager).
1- so in tools component i have a function that triggered when a user clicks the button
( this.$emit('theme-requested'); )
2- im listening for the event on my main blade page where the root div located id="designer" and where i declared both component (see above)
<theme-manager @theme-requested="showThemeManager"></theme-manager>
<tools></tools>
3- on my main js file i have a function that will show alert('')
methods: {
showThemeManager : function(){
alert();
},
}
4- the alert will be replaced with other function its just for testing the code,
5- the problem is the alert has never be triggered, i just cant make the $emitt() function to work on my app.
I hope sombody have a fix for this, Waiting for assistant ASAP.