nandi95 / vue-toastify

🔥 Simple, extendable, dependency free notification plugin. 🔥
https://vue-toastify.netlify.app/
MIT License
228 stars 12 forks source link

Error in mounted hook: "TypeError: Cannot read property '$on' of undefined" #5

Closed bedus-creation closed 4 years ago

bedus-creation commented 5 years ago

Solved

I was not using eventBus which causes problem. Solved for laravel projects,

// app.js
window.EventBus = new Vue();;
window.flash = function (message, type) {
    let statusObject={
        title: type+ " !!!",
        type:type,
        body: message,
        defaultTitle: true
    }
    EventBus.$emit('vtNotify', statusObject);
};

// vue-error.blade.php

@if(Session::has('success'))
<script>
    window.flash("{{session('success')}}", "success");

</script>
@endif

@if(Session::has('error'))
<script>
    window.flash("{{session('error')}}", "error");

</script>
@endif
@foreach($errors->all() as $error)
<script>
    window.flash("{{$error}}", "error");
</script>

@endforeach
bedus-creation commented 4 years ago

Bug In new Version 1.8.0

The above code used to work perfect with version 0.4.5. Now got new error. Template or render function not defined.

My template file is

<div id="app">
      <vue-toastify></vue-toastify>
</div>
nandi95 commented 4 years ago

Since 0.4.5 there has been a major version change with breaking changes.

I advise you to read the updated documentation and update your logic inline with the new methods or only allow minor changes for this package in your packages.json