路由跳转和传参

import { defineComponent, onMounted, reactive, readonly, ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';

export default defineComponent({
  name: 'Login',
  setup() {
    const router = useRouter(), route = useRoute();
    const submitForm = () => {
      formRef.value?.validate((valid) => {
        if (valid) {
          login({ strategy: 'local', ...ruleForm })
            .then((res: any) => {
            // 获取参数和路由跳转
              const redirect: string = route.query && route.query.redirect;
              if (redirect) {
                router.replace(redirect);
              } else {
                router.push('/home');
              }
              return true;
            })
            .catch((e) => {
              ...
            });
        } else {
         ...
          return false;
        }
      });
    };
    return { ..., submitForm };
  }
});
Logo

前往低代码交流专区

更多推荐