当前位置: 代码迷 >> 综合 >> async 和 await 和箭头函数
  详细解决方案

async 和 await 和箭头函数

热度:113   发布时间:2023-11-21 15:29:40.0

方式一

import store from '@/store'
import router from '@/router'async function logout() {
    await store.dispatch('user/logout')let autoLogin = falseif (localStorage.loginInfo) {
    autoLogin = JSON.parse(localStorage.loginInfo).autoLogin}router.push({
    path: `/login?redirect=${
      this.$route.fullPath}`,query: {
    autoLogin: autoLogin ? 1 : 0}})sessionStorage.clear()
}export default logout

方式一

import store from '@/store'
import router from '@/router'export const logout = async() => {
    await store.dispatch('user/logout')let autoLogin = falseif (localStorage.loginInfo) {
    autoLogin = JSON.parse(localStorage.loginInfo).autoLogin}router.push({
    path: `/login?redirect=${
      this.$route.fullPath}`,query: {
    autoLogin: autoLogin ? 1 : 0}})sessionStorage.clear()
}
  相关解决方案