Reputation: 417
I am trying to add toastr in my vue project. but I am having this error in console--
Uncaught TypeError: Cannot read properties of undefined (reading 'use')
this is my code in app.js---
import Vue from 'vue';
import './bootstrap';
import { createApp } from 'vue';
import CreateCart from './components/CreateCart.vue';
import CxltToastr from 'cxlt-vue2-toastr';
import 'cxlt-vue2-toastr/dist/css/cxlt-vue2-toastr.css'
var toastrConfigs = {
position: 'top right',
showDuration: 2000,
timeOut: 5000,
}
Vue.use(CxltToastr, toastrConfigs)
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
const app = createApp({});
app.component('create-cart', CreateCart);
app.mount('#app');
How do I solve this?
Upvotes: 0
Views: 1181
Reputation: 634
If you're using Vue 3, the correct way to do it is:
import { createApp } from "vue";
import App from "./App.vue";
import CxltToastr from 'cxlt-vue2-toastr';
const app = createApp(App);
const toastrConfigs = {
position: 'top right',
showDuration: 2000,
timeOut: 5000,
}
app.use(CxltToastr, toastrConfigs).mount('#app');
I hope it helps you
Upvotes: 1