zoukankan      html  css  js  c++  java
  • vue的toast组件封装

    思路很简单:

    样式思路:

    1.设置一个一定大小的盒子,然后给盒子设置背景颜色,再设置文字颜色,再来个固定定位脱离文档流就好了。

    代码逻辑思路:

    设置一个属性,控制toast弹出的状态显示与否,然后在设置个定时器,过一定事件,修改toast组件为不可见即可。

    代码:

        <template>
        <div class="toast" v-show="isShow">
          <div>{{message}}</div>
        </div>
      </template>
      <script>
        export default{
          name:'Toast',
          props:{
            // message:{
            //   type:String,
            //   default:''
            // }
          },
          data(){
            return{
              message:'',
              isShow:false
            }
          },
          methods: {
            show(message,duration=2000){
              this.isShow = true;
              this.message = message;
              setTimeout(() => {
                this.isShow = false;
                this.message = '';
              },duration)
            }
          },
        }
      </script>
      <style scoped>
       .toast{
         position: fixed;
         top:50%;
         left:50%;
         /* 根据自己本身宽高偏移 */
         transform: translate(-50%,-50%);
         padding:8px 10px;
         color: #fff;
         background-color: rgba(0, 0, 0, 0.7);
         z-index: 999;
       }
      </style>
    穷则独善其身,达则兼济天下……
  • 相关阅读:
    pandas之DataFrame
    python浅拷贝和深拷贝
    Numpy 机器学习三剑客之Numpy
    django--验证码功能实现
    python基础题
    python武器库
    django-rest-framework
    django--admin组件
    【转载】关于DBUtils中QueryRunner的一些解读
    【转载】java中的反射
  • 原文地址:https://www.cnblogs.com/hmy-666/p/14520698.html
Copyright © 2011-2022 走看看