周周清(1)

项目进度:

最近一直在搭建环境,都没写什么:登陆页面采用登陆注册在同一个界面,用v-if进行渲染,并且借助validation插件中的yup神器进行校验,





对于请求进行封装,设置请求拦截器和响应拦截器:

import { useUserStore } from '@/stores'
import { ElMessage } from 'element-plus'
import router from '@/router'
import axios from 'axios'
const baseURL = 'https://big-event-vue-api-t.itheima.net'
const instance = axios.create({
  baseURL,
  timeout: 10000
  //   headers: { 'X-Custom-Header': 'foobar' }
})
// Add a request interceptor
axios.interceptors.request.use(
  (config) => {
    // 携带token
    // Do something before request is sent
    const useStore = useUserStore()
    if (useStore.token) {
      config.headers.Authorization = useStore.token
    }
    return config
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error)
  }
)

// Add a response interceptor
axios.interceptors.response.use(
  function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    if (response.data.code === 0) {
      return response
    }
    ElMessage.error(response.data.message || '服务异常')
    return Promise.reject(response.data)
  },
  function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    //错误的特殊情况401 权限不足或者token过期=》拦截到登录
    if (error.response?.status === 401) {
      router.push('/login')
    }
    //错误的默认情况
    ElMessage.error(error.response.data.message || '服务异常')
    return Promise.reject(error)
  }
)

export default instance
export { baseURL }

封装接口:

import request from '@/utils/request'
//注册接口
export const userRegisterService = ({ email, password, repassword }) => {
  return request.post('/api/reg', { email, password, repassword })
}

//登录接口
export const userLoginService = ({ userAccount, password }) => {
  return request.post('/api/login', { userAccount, password })
}


这周答辩过后实在是看到了很大的不足,从这周起要开始认真了;这周的话应该要写完登陆注册jwt和修改个人资料,然后如果能多写一点的话可以适当加上一个搜索分页;

然后,激励自己:

周周清(1)_第1张图片

你可能感兴趣的:(总结专场,javascript,前端)