首頁  >  問答  >  主體

javascript - vue如何在進入下一個頁面前請求資料後如果code不等於200就不進入下一個頁面?

資料是在進入頁面之前請求的,這裡我就有一個需求,就是如果後端的code不等於200就提示使用者一些錯誤訊息,同時阻止使用者進入下一個頁面。看了下官網如果想中斷導航可以用next(false),但是這地方我return false為什麼不行,求解。

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 天前540

全部回覆(1)我來回復

  • 阿神

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

    return false // 這裡怎麼寫才能不進入下一個頁面

    next(false)

    else

    next()

    回覆
    0
  • 取消回覆