尝试在现有项目中运行Modal组件VueJS

时间:2018-06-19 12:01:59

标签: vue.js modal-dialog box

我制作了一个单独的.vue文件,在其中放置了Modal Box的“模板”和所需的CSS(稍后将其移至main.css)。我需要的功能是-在Data.vue主页上,客户端单击该按钮并打开一个“模式框”,他/她可以在其中编写消息并将其发送给我们。

modalTest.vue

.students-container ul {
    list-style-type: none;
    height: auto;
    margin: 1em auto;
    overflow: hidden;
    background: white;
    position: relative;
    box-sizing: border-box;
    padding-left:5px;
}

.students-container .student-container{
    top: 6em;
    position: relative;
    box-sizing: border-box;
    animation: marquee 20s linear infinite;
    -ms-animation: marquee 20s linear infinite;
}

.students-container .student-container  a{
    display: flex; 
    align-items: center;
    margin-bottom: 15px;
}   

.students-container .student-container .student-profile-image-container{
  width:100px;
  height:auto;
}

.students-container .student-container .student-profile-image-container img{
    max-width: 100%;
    max-height: 100%;
}

.students-container .student-container   
.student-details-container {
  max-width: 480px;
}

.students-container:hover .student-container {
    animation-play-state: paused;
}


// media query
@media (max-width: 1440px)
.students-container .student-container   
.student-details-container {
    max-width: 280px;
}

/* Make it move! */

@keyframes marquee {
    0% {
        top: 6em
    }
    100% {
        top: calc(-500px - 6em)
    }
}

@-ms-keyframes marquee {
    0% {
        top: 6em
    }
    100% {
        top: calc(-500px - 6em)
    }
}

我添加了需要单击的按钮,以便在项目的页面之一中弹出“模式框”。

Data.vue

<div class="students-container">
  <ul class="students-list">
    <li class="student-container">
      <a href="#">
        <div class="student-profile-image-container">
       <img src="https://studentprivacypledge.org/wp-content/uploads/2016/09/SPP_Pledge_2-1500x900.jpg">
        </div>
        <div class="student-details-container">
           It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
        </div>
      </a>
    </li>
    <li class="student-container">
      <a href="#">
        <div class="student-profile-image-container">
       <img src="https://studentprivacypledge.org/wp-content/uploads/2016/09/SPP_Pledge_2-1500x900.jpg">
        </div>
        <div class="student-details-container">
           It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
        </div>
      </a>
    </li>
    <li class="student-container">
      <a href="#">
        <div class="student-profile-image-container">
       <img src="https://studentprivacypledge.org/wp-content/uploads/2016/09/SPP_Pledge_2-1500x900.jpg">
        </div>
        <div class="student-details-container">
           It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
        </div>
      </a>
    </li>
    <li class="student-container">
      <a href="#">
        <div class="student-profile-image-container">
       <img src="https://studentprivacypledge.org/wp-content/uploads/2016/09/SPP_Pledge_2-1500x900.jpg">
        </div>
        <div class="student-details-container">
           It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
        </div>
      </a>
    </li>
    <li class="student-container">
      <a href="#">
        <div class="student-profile-image-container">
       <img src="https://studentprivacypledge.org/wp-content/uploads/2016/09/SPP_Pledge_2-1500x900.jpg">
        </div>
        <div class="student-details-container">
           It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
        </div>
      </a>
    </li>
  </ul>
</div>

最后但并非最不重要的 main.js

<template>
  <transition name="modal">
    <div class="modal-mask">
      <div class="modal-wrapper">
        <div class="modal-container">

          <div class="modal-header">
            <slot name="header">
              default header
            </slot>
          </div>

          <div class="modal-body">
            <slot name="body">
              default body
            </slot>
          </div>

          <div class="modal-footer">
            <slot name="footer">
              default footer
              <button class="modal-default-button" @click="$emit('close')">
                OK
              </button>
            </slot>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<style>
  .modal-mask {
    position: fixed;
    z-index: 9998;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .5);
    display: table;
    transition: opacity .3s ease;
  }

  .modal-wrapper {
    display: table-cell;
    vertical-align: middle;
  }

  .modal-container {
    width: 300px;
    margin: 0px auto;
    padding: 20px 30px;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
    transition: all .3s ease;
    font-family: Helvetica, Arial, sans-serif;
  }

  .modal-header h3 {
    margin-top: 0;
    color: #42b983;
  }

  .modal-body {
    margin: 20px 0;
  }

  .modal-default-button {
    float: right;
  }

  .modal-enter {
    opacity: 0;
  }

  .modal-leave-active {
    opacity: 0;
  }

  .modal-enter .modal-container,
  .modal-leave-active .modal-container {
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
  }
</style>

那是我到目前为止所做的。但是,当我单击Data.vue页面中的按钮时,什么也没有发生。查看控制台,没有有关此问题的信息。也许我误会了一些非常愚蠢的东西,但是现在我找不到任何错误。

1 个答案:

答案 0 :(得分:0)

在子页面的数据返回中放入showModal:false可解决此问题:)感谢@Vamsi Krishna