Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用路由器推送内部打开功能-Vue2_Javascript_Vue.js - Fatal编程技术网

Javascript 使用路由器推送内部打开功能-Vue2

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' }) } }) } } 但

使用这个库。代码的目的是当用户在sweetalert的模式窗口中单击“确定”时重定向到另一个路径:

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' })
}