[英]@aws-amplify/ui-components - Trigger Toast with Custom Message
I'm using @aws-amplify/ui-components
library which is deprecated (for Vue 2).我正在使用已弃用@aws-amplify/ui-components
库(对于 Vue 2)。 It comes with a Toast component ( <amplfy-toast />
)which alerts error messages in the top of the screen.它带有一个 Toast 组件 ( <amplfy-toast />
),它会在屏幕顶部提醒错误消息。 In my Vue.js component I want to trigger message but programatically where the console.log()
is:在我的 Vue.js 组件中,我想以编程方式触发消息,其中console.log()
是:
watch: {
authState: {
async handler(state) {
const data = this.authData
if (state === 'signedin') {
try {
const local = await this.axios.post('/api/v1/authentication/login', {
token: data.getSignInUserSession().getIdToken().getJwtToken()
})
if ( ! local.data.error) {
await this.$store.dispatch('login', data)
}
} catch (error) {
console.log(error) // Trigger toast here.
}
}
},
immediate: true
}
},
How can I do this?我怎样才能做到这一点?
You can do this with dispatchToastHubEvent()
function or simply call:您可以使用dispatchToastHubEvent()
function 或简单地调用:
Hub.dispatch('UI Auth', {
event: 'ToastAuthError',
message: error.message
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.