Promise error: Uncaught (in promise) Error: Timeout at eval

A teaching video on the Mujie website. QQ Music"s data is obtained across domains through jsonp. The console has been reporting errors

.
// jsonp.js

import originJSONP from "jsonp"

export default function jsonp(url, data, options) {
  url += (url.indexOf("?") < 0 ? "?" : "&") + params(data)
  
  console.log(url, data, options)

  return new Promise((resolve, reject) => {
    originJSONP(url, options, (err, data) => {
      if (!err) {
        console.log("right")
        resolve(data)
      } else {
        console.log("error")
        reject(err)
      }
    })
  })
}

function params(data) {
  let url = ""
  for (let i in data) {
    let value = data[i] !== undefined ? data[i] : ""
    url += `&${i}=${encodeURIComponent(value)}`
  }
  return url ? url.substring(1) : ""
}
// recommend.js

import jsonp from "common/js/jsonp"
import {commonParams, options} from "./config"

export function getRecommend() {
  const url = "https://c.y.qq.com/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg"

  const data = Object.assign({}, commonParams, {
    platform: "h5",
    uin: 0,
    needNewCode: 1
  })

  return jsonp(url, data, options)
}
// recommend.vue

  created() {
    this._getRecommend()
  },
  methods: {
    _getRecommend() {
      getRecommend().then((res) => {
        if (res.code === ERR_OK) {
          console.log(res.data.slider)
        }
      })
    }
  }

it is correct to print url across domains

clipboard.png

clipboard.png

can"t find out what the problem is, solve

Aug.05,2021

your Promise remember catch make a mistake, and have the habit of catch .
should be network request timeout , it's the server request

_getRecommend() {
  getRecommend().then((res) => {
    if (res.code === ERR_OK) {
      console.log(res.data.slider)
    }
  })
  .catch(err => {
    console.log(err) // catchtimeout
  })
}
Menu