Home  >  Q&A  >  body text

javascript - How does vue not go to the next page if the code is not equal to 200 after requesting data before entering the next page?

The data is requested before entering the page. I have a requirement here, that is, if the backend code is not equal to 200, it will prompt the user with some error information and prevent the user from entering the next page. After looking at the official website, if you want to interrupt navigation, you can use next(false), but why does it not work if I return false here? Please help.

beforeRouteEnter (to, from, next) {
        Vue.$uop.loading.show({
          text: '加载中'
        })
        reqData.req({
          apiName: 'getAddress'
        }).then((res) => {
          next((vm) => {
            vm.$uop.loading.hide()
            res = res.data
            if (res && res.code !== 200) {
                vm.$uop.toast.show({
                    type: 'text',
                    text: res.message
                })
                return false // 这里怎么写才能不进入下一个页面
            }
          })
        }).catch((error) => {
          Vue.$uop.loading.hide()
          Vue.$uop.toast.show({
            type: 'text',
            text: '请求地址数据异常'
          })
        })
PHP中文网PHP中文网2710 days ago539

reply all(1)I'll reply

  • 阿神

    阿神2017-05-19 10:30:05

    return false // How to write here so as not to enter the next page

    next(false)

    else

    next()

    reply
    0
  • Cancelreply