首页 > 解决方案 > 当我在惯性.js 中使用它时,vue-toastr 不起作用

问题描述

我正在使用 Inertia.js 创建一个页面。当我在 Vue 模板文件中添加 vue-toastr 时,它不起作用。我不知道如何解决它。请建议我

这是 app.js

import Vue from 'vue'
import { createInertiaApp } from '@inertiajs/inertia-vue'

import Toastr from 'vue-toastr'
Vue.use(Toastr);

createInertiaApp({
  resolve: name => require(`./Pages/${name}`),
  setup({ el, App, props }) {
    new Vue({
      render: h => h(App, props),
    }).$mount(el)
  },
})

这是 vue 模板文件

<script>
 import Master from './Layout/Master';
  export default{
    name:"Home",
    created(){
      this.$toastr.s("success","it is working");
    },
  components:{Master}
  };
</script>

标签: javascriptphplaravelvue.jsinertiajs

解决方案


use 

the import Toastr from 'vue-toastr' 

directly on your vue instance not in app.js like this : 

<script>
 import Master from './Layout/Master';
 import Toastr from 'vue-toastr'

  export default{
    name:"Home",
    data()
   {
       return 
          {
            toastr: Toastr
           }
      }
,
    created(){
      this.$toastr.s("success","it is working");
    },
  components:{Master}
  };
</script>

推荐阅读