ElMessageBox的使用

一般情况下ElMessageBox会配合Button类的组件来使用,但是默认的情况下ElMessageBox的确定键,取消键或者其它内容是英文,新手会很疑惑怎么去修改这些

例如:

<script lang="ts" setup>
    
import { ElMessage, ElMessageBox } from 'element-plus'
import type { Action } from 'element-plus'

const open = () => {
  ElMessageBox.alert('This is a message', 'Title', {
    confirmButtonText: 'OK',
    callback: (action: Action) => {
      ElMessage({
        type: 'info',
        message: `action: ${action}`,
      })
    },
  })
}


</script>

<template>
    <el-button plain @click="open">Click to open the Message Box</el-button>
</template>

代码不能直接在HTML中改,此时需要用到ElMessageBox的配置选项

格式:ElMessageBox.类型(“显示的内容”,“标题”,{

配置项

})

例如:

ElMessageBox.alert('这是一段内容', '标题名称', {  

  confirmButtonText: '确定', // 设置确定按钮的文本  

  type: 'warning', // 设置消息框的类型  

  callback: action => {  

    if (action === 'confirm') {  

      // 当用户点击确定按钮时执行的回调  

      console.log('用户点击了确定按钮');  

    }  

  }  

});  

  

// 或者,如果你需要更多按钮选项,可以使用 confirm 方法  

ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {  

  confirmButtonText: '确定',  

  cancelButtonText: '取消',  

  type: 'warning',  

  callback: action => {  

    if (action === 'confirm') {  

      // 用户点击确定  

      console.log('用户点击了确定按钮');  

    } else if (action === 'cancel') {  

      // 用户点击取消  

      console.log('用户点击了取消按钮');  

    }  

  }  

});

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值