Javascript 使用路由器推送内部打开功能-Vue2
使用这个库。代码的目的是当用户在sweetalert的模式窗口中单击“确定”时重定向到另一个路径:Javascript 使用路由器推送内部打开功能-Vue2,javascript,vue.js,Javascript,Vue.js,使用这个库。代码的目的是当用户在sweetalert的模式窗口中单击“确定”时重定向到另一个路径: methods: { customMethod () { this.$swal({ title: resp.data.displayText, type: 'success', onClose () { this.$router.push({ name: 'AnotherPage' }) } }) } } 但
methods: {
customMethod () {
this.$swal({
title: resp.data.displayText,
type: 'success',
onClose () {
this.$router.push({ name: 'AnotherPage' })
}
})
}
}
但它不起作用,因为我得到一个错误,关于
无法读取未定义的属性“$router”
,已解决,使用箭头函数:
onClose: () => {
this.$router.push({ name: 'AnotherPage' })
}
使用箭头函数求解:
onClose: () => {
this.$router.push({ name: 'AnotherPage' })
}