vue组件弹窗

∥☆過路亽.° 提交于 2019-12-23 21:46:05

定义弹窗组件

  先写一个普通的vue组件,其显示的内容就是弹窗的内容。

  文件的位置 /src/views/toast/toast.vue

  

<template>
  <div class="wrap">已经是最底部了</div>
</template>
<script>
export default {
  name: 'Toast'
}
</script>

<style lang="scss" scoped>
  .wrap{
    position: fixed;
    left: 50%;
    top:50%;
    background: rgba(0,0,0,.65);
    padding: 10px;
    border-radius: 5px;
    transform: translate(-50%,-50%);
    color:#fff;
  }
</style>

  

引用弹窗组件

 组件注册定义好了,那接下来就是引入组件,使用弹窗组件了。

<template>
  <div class="movies-list">
    <!-- 其他代码 -->
  这里写页面的其他代码
    <!-- 其他代码 -->
    <toast v-if="cont"></toast>
  </div>
</template>

<script>
// 引入弹窗组件
import toast from './toast/toast';
export default {
  name: 'Homepage',
  components: {toast},
  data() {
    return {
      cont: false
    }
  },

  created () {
      let _this = this;
    if(某个条件为真) {
        _this.cont = true;
        // 显示1s
        setTimeout(function(){
          _this.cont = false;
        }, 1000);
      }
  }
}
</script>

 

效果图

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!