LoginSignup
10
8

More than 5 years have passed since last update.

Vue.jsでlazyloadを実装

Posted at

意外に自作するコードが少なかったので、書いてみました。

ソース

<div id="vue-instance">
  <img src="loading.gif">// ローディング画像
  <img src="hoge.jpg" v-on:load="hideLoading">// 表示させたい画像
</div>
var vm = new Vue({
  el: '#vue-instance',
  methods: {
      hideLoading: (event) => {
        event.target.previousElementSibling.remove();
      }
    }
});

画像がロードされたタイミングでメソッドを呼び出してそこで
ローディング画像を削除していま

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8