指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

nuxt3 获取接口数据遇到的问题,通过useFetch 在测试服务器没法获取到数据,但是 $fetch 可以;不知道为什么,设置server:false的时候 是可以拿到数据的,本地环境 dev/build 都是没问题的,但是放到测试服务器就有问题,不知道是不是和nodejs 版本有关,我本地是:v19.3.0 测试环境是:v18.15.0

  created() {
    this.getCourseDetail();
  },
methods: {
     getCourseDetail: async function () {
       const res = await $fetch('/api/course/' + this.$route.params.id, {
         method: 'get',
         headers: {'X-Requested-With': 'XMLHttpRequest'},
       })

       console.log(res)

       if (res){
         if (res.code == 0){
               this.courseDetail.id = res.data.id
               this.courseDetail.title = res.data.title
         }else {
           this.$toast.info(res.msg)
         }
       }else {
         this.$toast.error('require api failed')
       }

       // const {data, error} = await useFetch('/api/course/' + this.$route.params.id, {
       //   method: 'get',
       //   headers: {'X-Requested-With': 'XMLHttpRequest'},
       // })

       // if (error._value) {
       //   this.$toast.error(error._value.data.msg)
       // } else {
       //   if (data._value.code === 0) {
       //     console.log(11111)
       //     this.courseDetail.id = data._value.data.id
       //     this.courseDetail.title = data._value.data.title
       //   } else {
       //     this.$toast.info(data._value.msg)
       //   }
       // }
     }
     }