欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Vue3 Toast 吐丝插件开发

程序员文章站 2022-05-17 10:07:51
...
// src/toast.vue
<template>
  <transition name="alert-fade">
    <div id="toast"
         v-show="visible"
         class="dialog-tips dialog-center">
      {{message}}
    </div>
  </transition>
</template>
<script>
import { ref } from 'vue'
export default {
  name: 'toast',
  setup() {
    let visible = ref(false)
    let message = ref('')

    return {
      visible,
      message
    }
  },
}
</script>
<style lang="scss" scoped>
.alert-fade-enter-active,
.alert-fade-leave-active {
  transition: opacity 0.3s;
}
.alert-fade-enter,
.alert-fade-leave-to {
  opacity: 0;
}
.dialog-tips {
  position: fixed;
  z-index: 100;
  min-width: 100px;
  padding: 15px;
  line-height: 15px;
  border-radius: 15px;
  white-space: nowrap;
  background-color: rgba(0,0,0,.8);
  box-shadow: 8px 8px 8px 1 rgba(0,0,0,.8);
  text-align: center;
  color: #fff;
  font-size: 15px
}
.dialog-center {
  top: 20%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>
Vue3 Toast 吐丝插件开发

欢迎关注我的公众号