LoginSignup
5
7

More than 3 years have passed since last update.

【Vue】モーダルコンポーネント(コピペ用)

Posted at

概要

  • 何の変哲もないモーダルコンポーネントです。
  • 業務でもよく使うのでコピペ用に残しておきます。
  • 動作確認はお手軽なcodesandboxで!!
/components/Modal.vue
<template>
  <div>
    <div class="el-modal" :aria-hidden="isOpen ? 'false' : 'true'">
      <div class="el-modal__holder">
        <button @click="close()">閉じる</button>
      </div>
      <div class="el-modal__overlay"></div>
    </div>
    <button @click="open()">開く</button>
  </div>
</template>

<script>
export default {
  name: "Modal",
  data: function() {
    return {
      isOpen: false
    };
  },
  methods: {
    open: function() {
      this.isOpen = true;
    },
    close: function() {
      this.isOpen = false;
    }
  }
};
</script>
<style lang="sass">
  .el-modal
    visibility: hidden

    &__holder
      position: fixed
      z-index: 1100
      background-color: blue
      width: 50%
      height: 50%

    &__overlay
      position: fixed
      z-index: 1000
      background-color: red
      width: 100%
      height: 100%

    &[aria-hidden=false]
      visibility: visible
</style>
App.vue
<template>
  <div id="app">
    <modal/>
  </div>
</template>

<script>
import Modal from "./components/Modal";

export default {
  name: "App",
  components: {
    Modal
  }
};
</script>
5
7
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
5
7