【发布时间】:2021-03-18 13:10:45
【问题描述】:
我需要你更深入地了解我如何使用 vueJS。
我的应用
我有一个Login.vue,它正在调用一个函数logUser() from UserActions.js,它正在调用我的AxiosFacade.js' function postRequest()
我使用插件以createApp(App).use(Toaster).mount('#app') 显示烤面包机信息并使用this.$toast.show(`Default Toast Message`); 调用我的烤面包机
我想做的事
我想从 AxiosFacade.js 中我的 axios 调用的 catch 部分调用我的函数 this.$toast.show
类似:
return axios.post(`${serv}/${ressource}`,
{
data: params,
},
{headers: {'Authorization': 'Bearer ' + token}})
.then((response) => response = response.data)
.catch((err) => {
this.$toast.error(err.response.data.message);
throw err.response.data.message
})
但我不太明白如何从 .js 和 .vue 文件中创建链接
PS:下一步将是拥有我自己的 Toaster.vue 组件,并在我的 AxiosFacade.js 中显示/隐藏它,如果你也有这方面的提示:)
谢谢!
【问题讨论】:
-
this不能在自定义 js 文件中工作,因为它不是 vue 参考 -
是的,我从控制台中看到的
undefined看到了这个,但我不知道如何访问我的函数 -
需要从main.js文件中导入vue
-
很抱歉,我可能需要更多信息才能完成所有流程。我在 main.js 中
import Vue from 'vue',但是如何在另一个文件中调用我的函数?
标签: javascript vue.js plugins toast