使用此库 vue-sweetalert2 。代码的目的是,当用户在 sweetalert 的模式窗口中单击“确定”时,重定向到另一个路径:
methods: {
customMethod () {
this.$swal({
title: resp.data.displayText,
type: 'success',
onClose () {
this.$router.push({ name: 'AnotherPage' })
}
})
}
}
但它不起作用,因为我收到有关无法读取未定义的属性“$router”的错误
。
最佳答案
解决了,使用箭头函数:
onClose: () => {
this.$router.push({ name: 'AnotherPage' })
}
关于javascript - 在 sweetalert onOpen 函数中使用路由器推送 - Vue2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52584867/