指尖上的记忆指尖上的记忆
首页
  • 基础
  • 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通过接口获取数据

methods:{
    // getCourseDetail: async function () {
    //   let data = await useFetch('/api/course-detail?id='+this.$route.query.id)
    //   console.log('data is:', data)
    // }
    // getCourseDetail:  function () {
    //   let data =  useFetch('/api/course-detail', {query: {id:this.$route.query.id}})
    //   console.log('data is:', data)
    // }

    getCourseDetail:  async function () {
      let data = await useFetch('/api/course-detail', {method: 'post', body: {id: this.$route.query.id}, server: false})
      console.log('data is:', data.data._value.data)
      console.log('data is:', data.data._value.code)
      console.log(data)

      console.log(utils.isLogin())
      console.log(utils.getUserInfo())
    }
  }

注意useFetch 后的接口地址一定要加 / ,否则就是相对地址,可能会被自动添加前缀,导致接口报错,泪奔呀。。。,比如:useFetch('/api/course-detail', {query: {id:this.$route.query.id}}) 写成了useFetch('api/course-detail', {query: {id:this.$route.query.id}}),那么最后接口地址可能变成了:course/api/course-detail,而不是 api/course-detail