BillBie

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

vue 的toast组件

直接使用第三方库:https://github.com/Maronato/vue-toastification

 

1.npm install --save vue-toastification@next


2.在main.js导入和使用
import Toast from "vue-toastification";
// Import the CSS or use your own!
import "vue-toastification/dist/index.css";

const options = {
    // You can set your default options here
};

app.use(Toast, options);

3.option 常用设置:
{
containerClassName: "my-container-class",  //container使用自己的样式,不使用自己的则不用配置
transition: false, //不使用出现特效
maxToasts: 10,
newestOnTop: true
}

在vue文件的使用
setup方法
   setup() {
      // Get toast interface
      const toast = useToast();

      // These options will override the options defined in the "app.use" plugin registration for this specific toast
      // Make it available inside methods
      return { toast }
    },
调用
复制代码
  methods:{
    btn_click(){
      console.log('aaa')
      this.toast.error("待开发中...",{
         position: "top-center", //出现的位置
        timeout: 2000,
        closeOnClick: false,
        closeButton: false,
        hideProgressBar: true,
        icon:false,

      });
    }
  }
复制代码

 

当然可以对默认的样式修改

复制代码
  /* When setting CSS, remember that priority increases with specificity, so don't forget to select the existing classes as well */

    /* This will only affect the top-right container */
    .Vue-Toastification__container.top-center.my-container-class{
        /*top: 10em;*/

      align-items: center;
          position: absolute;
        left: 50%;
          top: 50%;
          transform: translate(-50%,-50%);
      justify-content: center;
    /*width: 100%;*/

    }

    /* This will affect all 6 containers */
    .Vue-Toastification__toast{
        /*position: fixed;*/
      background-color: #c0c0c0;
      opacity: 0.8;
      max-width: 50%;
      min-width: 10%;
      align-items: center;
      color: black;

    }
    .Vue-Toastification__toast-body{

    /*!*width: 100%;*!*/
     text-align: center;
    /* justify-content: center;*/
    align-items: center;

      line-height: 24px;
    font-size: 16px;
    word-break: break-word;
    white-space: pre-wrap;
    }
复制代码

 

 





posted on   BillBie  阅读(584)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示