h***@sina.com
h***@sina.com
  • 发布:2023-08-31 12:07
  • 更新:2023-08-31 14:53
  • 阅读:157

登录之后,页面没有自动跳转, 需要手动刷新一下

分类:uni-app
  1. 登录成功之后,页面没有跳转,需要手动刷新一下,才到目标页面。代码如下:

<template>
<view class="login">
<uni-card :is-shadow="false" :border="false">
<view class="login-title">
登录
</view>
<uni-forms ref="loginForm" :modelValue="login" label-position="left">
<uni-forms-item label="账号" required>
<uni-easyinput v-model="login.username" placeholder="账号" />
</uni-forms-item>
<uni-forms-item label="密码" required>
<uni-easyinput type="password" v-model="login.password" placeholder="密码" />
</uni-forms-item>
<uni-forms-item label="验证码" required>
<uni-easyinput v-model="login.captcha" placeholder="验证码" />
</uni-forms-item>
<uni-forms-item label=" ">
<image :src="captchaUrl" style="height: 40px;width: 150px;" @click="getCaptchaUrl"></image>
</uni-forms-item>
</uni-forms>
<view>
<button type="primary" @click="loginSubmit">登录</button>
</view>
</uni-card>
</view>
</template>

<script>
import {getUuid} from '@/utils/index';
import {useLoginApi} from '@/api/login';

export default {
data() {
return {
login:{
username: '',
password: '',
captcha: '',
uuid: ''
},
captchaUrl: ''
}
},
onLoad() {
if (this.$store.state.user.token){
uni.reLaunch({
url: '/pages/index/post'
});
}else {
this.getCaptchaUrl();
}
},
methods: {
getCaptchaUrl() {
this.login.uuid = getUuid();
this.captchaUrl = ${uni.$u.http.config.baseURL}/captcha?uuid=${this.login.uuid};
},
loginSubmit() {
useLoginApi(this.login).then(res =>{
this.$store.commit('user/setToken', res.data.token)

            uni.navigateTo({  
                url: '/pages/indes/post'  
            });  
            setTimeout(() => {  
                        console.log('after reLaunch');  
                    }, 1000);   
        }).catch(e =>{  
            this.getCaptchaUrl();  
        })  
    }  
}  

}
</script>

<style lang="scss" scoped>
.login {
display: flex;
flex-direction: column;
justify-content: center;
}
.login-title{
margin: 50px 0;
text-align: center;
font-size: 28px;
font-weight: bold;
color: rgb(60, 156, 255);
}
</style>

2023-08-31 12:07 负责人:无 分享
已邀请:
1***@163.com

1***@163.com

import {getUuid} from '@/utils/index'; import {useLoginApi} from '@/api/login'; export default { data() { return { login:{ username: '', password: '', captcha: '', uuid: '' }, captchaUrl: '' } }, onLoad() { if (this.$store.state.user.token){ uni.reLaunch({ url: '/pages/index/post' }); }else { this.getCaptchaUrl(); } }, methods: { getCaptchaUrl() { this.login.uuid = getUuid(); this.captchaUrl = ${uni.$u.http.config.baseURL}/captcha?uuid=${this.login.uuid}; }, loginSubmit() { useLoginApi(this.login).then(res =>{ this.$store.commit('user/setToken', res.data.token) uni.navigateTo({ url: '/pages/indes/post' }); setTimeout(() => { console.log('after reLaunch'); }, 1000); }).catch(e =>{ this.getCaptchaUrl(); }) } } } .login { display: flex; flex-direction: column; justify-content: center; } .login-title{ margin: 50px 0; text-align: center; font-size: 28px; font-weight: bold; color: rgb(60, 156, 255); }

1***@163.com

1***@163.com

单词写错还来提bug

  • h***@sina.com (作者)

    抱歉,我还是没看出来哪个单词错了。

    2023-09-04 10:46

  • h***@sina.com (作者)

    看到了,感谢

    2023-09-04 10:53

要回复问题请先登录注册