当我尝试在pwa中创建用户时,我会尝试显示一个通知。为此,我订阅了设置通知的突变,然后调用通知,但控制台上没有显示任何内容,也没有错误。
这就是我想要做的:
export default {
...,
mounted: function() {
var self = this
this.$store.subscribe(function(mutation, state) {
if (mutation === 'usuario/setError') {
self.$q.notify({
message: state.usuario.error.mensagem,
timeout: 3000,
type: state.usuario.error.sucesso ? 'positive' : 'negative',
position: 'top'
})
}
})
}
}
我尝试从qusar导入通知并调用Notify.create,但没有成功。
发布于 2018-04-17 07:53:28
我找到了一个解决方案,而不是使用subscribe,我可以使用vue中的watch,并在计算机上查看更改。这样:
export default {
...,
computed: {
error: function() {
return this.$store.state.usuario.error
}
},
watch: {
error: function(newError, oldError) {
console.log(newError)
this.$q.notify({
message: newError.mensagem,
timeout: 3000,
type: newError.sucesso ? 'positive' : 'negative',
position: 'top'
})
}
},
...
}
发布于 2019-02-01 19:50:06
尝试if (mutation.type === 'usuario/setError'),如果这不起作用,控制台日志突变查看类型是什么,并使用它。
https://stackoverflow.com/questions/49867254
复制相似问题