mickeyort 发表于 2022-6-29 15:21:03

Vue实现图片预加载




methods: {
    preload: function() {
      let imgs = [
      "static/img/back.gif",
      "static/img/correct.png",
      "static/img/cover.gif",
      "static/img/errExpress.png",
      "static/img/error.png",
      "static/img/ply.png",
      "static/img/q1.png",
      "static/img/q1a.png",
      "static/img/q1b.png",
      "static/img/q1c.png",
      "static/img/q1d.png",
      "static/img/share.png",
      "static/img/start.png",
      "static/img/stop.png"
      ]

      for (let img of imgs) {
      let image = new Image()
      image.src = img
      image.onload = () => {
          this.count++
          // 计算图片加载的百分数,绑定到percent变量
          let percentNum = Math.floor(this.count / 14 * 100)
          this.percent = `${percentNum}%`
      }
      }
    },

},
页: [1]
查看完整版本: Vue实现图片预加载