LoginSignup
0
3

More than 3 years have passed since last update.

Vue.jsでダイアログ

Last updated at Posted at 2019-11-23

html

<div id="app">
  {{ message }}
<button v-on:click="openDialog">ボタン</button>
</div>

Javascript

※ダイアログを表示するが、消す処理は入れてない

// ダイアログ用のVueのサブクラス作成
let dialog = Vue.extend({
  template: '<div>ダイアログ</div>'
});


var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue!'
  },
  methods: {
    openDialog: function () {
      // ダイアログ用のvueインスタンスを作成(el要素が無いためアンマウント状態)
      let daialogInstance = new dialog();
      // ダイアログ用のインスタンスをマウント
      let daialog = daialogInstance.$mount();
      // ダイアログの要素を#appの要素内にappendする
      this.$el.appendChild(daialog.$el);
    }
  }
});

CodePen:https://codepen.io/hukuzatsu/pen/ZEEZVjO?editors=1111
参考:https://kitak.hatenablog.jp/category/Vue?page=1493443912

0
3
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
0
3