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?
PHP中文网
PHP中文网 2017-05-19 10:28:05
0
1
534

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中文网

认证高级PHP讲师

reply all(1)
阿神

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

next(false)

else

next()

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!