【问题标题】:Vue-toastr and Vue2 how to set global options for toastr?Vue-toastr 和 Vue2 如何为 toastr 设置全局选项?
【发布时间】:2023-03-17 23:42:01
【问题描述】:

我在我的 Laravel 5.5 和 Vuejs 2 项目中使用 vue-toastr

祝酒词显示正常,但我想为祝酒词全局设置一些选项,例如位置...

我做不到。

在我的 app.js 文件中,我从 vue-toastr 导入了 toastr,需要样式,然后是 Vue.component('vue-toastr', Toastr);

我已经在我的 app.js 上尝试了this.$refs.toastr.defaultPosition = "toast-bottom-left",就像文档说的那样,但它给了我一个错误Cannot read property 'toastr' of undefined

有什么帮助吗?

【问题讨论】:

    标签: vue.js vuejs2 toastr


    【解决方案1】:

    in the documentation:

    添加组件 html: for vue 1.x

    <vue-toastr v-ref:toastr></vue-toastr> 
    

    添加组件 html: for vue 2.x

    <vue-toastr ref="toastr"></vue-toastr>
    

    然后就可以使用了

    this.$refs.toastr.defaultPosition = "toast-bottom-left"
    

    【讨论】:

    • 正如我在问题中所说的那样,我已经这样做了,但是在我的 app.js 中,这是我的主要 Vue 文件......但是我得到了一个错误。我不想每次调用 toastr 时都使用这个配置
    • @JDalri 不,您没有在问题中说您将组件添加到模板的任何地方。你只是说你注册了它。
    猜你喜欢
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    相关资源
    最近更新 更多