【问题标题】:vue-toastr doesn't work when I am using this in inertia.js当我在惯性.js 中使用它时,vue-toastr 不起作用
【发布时间】:2021-10-25 06:10:45
【问题描述】:

我正在使用 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>

【问题讨论】:

  • 您需要提供更多背景信息,我们才能为您提供帮助。
  • 我需要给你看哪些文件

标签: javascript php laravel vue.js inertiajs


【解决方案1】:
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>

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2021-05-30
  • 2021-08-03
  • 2018-12-09
  • 2022-10-14
  • 2018-05-11
  • 1970-01-01
  • 2021-06-25
  • 1970-01-01
  • 2023-02-07
相关资源
最近更新 更多