• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
芣莨朲
博客园    首页    新随笔    联系   管理    订阅  订阅

vue组件弹窗

定义弹窗组件

  先写一个普通的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>

 

效果图

 

posted @ 2019-02-13 17:03  芣莨朲  阅读(832)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3