javascript - 当我在惯性.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>
解决方案
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>
推荐阅读
- android - 离子电容器 AAPT:错误:资源 android:attr/dialogCornerRadius 未找到
- vb.net - 如何将客户端证书附加到 SOAP 请求?
- html5-video - 如何使用开源播放器在 VAST 4.2 中播放 hls?
- python - psycopg2.errors.StringDataRightTruncation:类型字符变化的值太长(255)
- go - 如何通过 ScanIndexForward 对 aws-sdk-go-v2 中的查询结果进行排序?
- java - Spring AspectJ AOP 方法未执行
- python - Python & Pandas:在 pd.read_excel 中读取 variable.content 会引发错误“文件不是 zipfile”
- android - 如何在 android 10 上获取 memInfo
- javascript - Bootstrap 5 工具提示中的 HTML
- python - 从熊猫数据框日期列中获取标准气象周