Vue.js dragendイベントを取得する

Vue.js dragendイベントを取得する

Vue.jsで、dragendイベントを取得するサンプルコードを記述してます。 「vue3」を使用してます。

環境

  • OS windows10 pro 64bit
  • Vue.js 3.2.2
  • Apache 2.4.43
  • ブラウザ chrome 92.0.4515.107

dragendイベントを取得

dragendイベントを取得するには、「v-on:dragend」を使用します。
「 v-on:dragend」は、「@dragend」と省略できます。

以下は、要素のドラッグを終了すると「ドラッグが終了しました」という文字列を表示するサンプルコードとなります。

※「vue3」は「cdn版」、デザインは「semantic-ui」を使用してます。

<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="utf-8">
  <title>mebeeサンプル</title>
  <!-- semantic.css  -->
  <link rel="stylesheet" type="text/css"
    href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
  <script src="https://unpkg.com/vue@next"></script>

</head>
<style>
  body>.grid {
    height: 100%;
  }
</style>

<body>
  <div id="app" class="ui grid middle aligned">

    <div class="row">
      <div class="column">

        <h2 class="ui gray header center aligned">{{val}}</h2>

        <!-- ドラッグする要素 -->
        <div @dragend="foo" class="ui info message container segment"
          style="width: 200px; padding: 20px; margin-bottom: 10px; border: 1px dashed #333333;">
          Hello Javascript!!
        </div>

      </div>
    </div>

  </div>
  <script>

    const hoge = {
      data() {
        return {
          val: ''
        }
      },
      methods: {
        foo: function (e) {
          this.val = 'ドラッグが終了しました'
        }
      }
    }

    Vue.createApp(hoge).mount('#app')

  </script>
</body>

</html>

ドラッグを終了すると文字列が表示されていることが確認できます。