关于前端的跨域问题如何解决?

这是一个简单的使用接口获取验证码并登录,请问代码中关于前端跨域withCredentials:true部分对吗?不对的话应该怎么做呢?谢谢大家!

methods: {
    async getCode() {
      const {data:res} = await this.$http.post('v1/captchas',{
        withCredentials:true
      });
      // console.log(res);
      this.code = res.code;
    },
    async login() {
        const {data:res} = await this.$http.post('v2/login',{
            username:this.userV,
            password:this.pwV,
            captcha_code:this.codeV
          },{
            withCredentials:true
            });
          this.$store.commit('addMyInfo',res)
        console.log(res);
        this.$router.push({
           path:'/profile',
        });
    }
}