zoukankan      html  css  js  c++  java
  • 20211122 VUE3控制台出现'Unhandled error during execution of component event handler'警告解决方法

    1. 如何出现‘Unhandled error during execution of component event handler’这句警告的?

    页面布局大概是这样子的:
    <template>
    <div class="container">
    // 搜索栏组件
    <search />

    // table 组件
    <et-talble>
    <template #action="row">
    // 这里引入table表格中操作栏的按钮组件,假设目前只有一个 编辑, 启用/禁用 按钮
    <operation-btns
    :row="row"
    @edit="handleEdit"
    @enable="handleEnable"
    />
    </template>
    </et-table>
    </div>
    </template>
    // 备注说明:暂不研究引入组件的内容
    <script>
    //这里放引入组件的文件路径
    export default{
    name:'xx',
    components:{
    search,
    etTable,
    operationBtns
    },
    data(){
    return {

    }
    },
    computed:{},
    watch:{},
    created(){},
    methods:{
    // 编辑
    handleEdit(){

    },
    // 启用/禁用
    async handleEnable(row){
    await this.$confirm('确定要启用/禁用这条数据吗?','提示',{
    confirmButtonText:'确定',
    cancelButtonText:'取消',
    type:'warning',
    })
    .then(async ()=>{
    // 这里处理相关业务逻辑
    await requestStatusApi();
    this.$message.success('操作成功')
    })
    // 重点***,如果这里少了catch这一步,就会报警告
    .catch(()=>{})
    }
    }
    }
    </script>
    <style scoped lang="scss"></style>

    2. 如何理解这句警告 'Unhandled error during execution of component event handler'

    Unhandled error during execution of component event handler 译为: 组件事件处理程序执行期间未处理的错误

    操作流程:
    点击启用/禁用按钮,提示弹窗 弹出,然后点击按钮
    - 确定按钮 - 走正常业务逻辑,没有出现这个警告。
    - 取消按钮 - 界面效果: 提示弹窗消失,然后出现警告内容。

    处理方法:
    就是: this.$confirm()方法未处理取消按钮触发的事件,所以就需要 catch 去捕捉这个错误即可。

    3. 关于 this.$alert 方法 点击关闭图标触发的回调方法

    <el-button type="text" @click="open">点击打开alert弹窗</el-button>

    open(){
    this.$alert('点击了alert弹窗','标题名称',{
    confirmButtonText:'确定',
    //
    callback: () => {
    // 点击弹窗里的 关闭图标 会触发这里的事件
    this.$message.info('点击关闭图标~~~')
    }
    })
    .then(() => {

    }).catch(()=>{

    })


    // $confirm 方法也是一样的
    this.$confirm('文本内容','弹窗标题',{
    confirmButtonText:'确定',
    cancelButtonText:'取消',
    type:'warning'
    }).then(()=>{
    // 点击确定会进这里面
    this.$message.success('操作成功')
    }).catch(()=>{
    // 点击取消会进这里面
    this.$message.info('取消成功')
    })
    }

    如果快乐太难,那祝你平安。
  • 相关阅读:
    [Linux]Vmwaer创建CENTOS7虚拟机[转]
    [游记]二访金陵
    [Android]ADB调试: SecurityException: Injecting to another application requires INJECT_EVENTS permission
    [操作系统]记一次未尽的三星 Galaxy A6s(SM-G6200)刷机过程
    [网络]NAT与内网穿透技术初探【待续】
    结构化系统建模之程序流程图|系统流程图|数据流图
    UML系统建模之用例视图
    [Linux]常用命令之【mkdir/touch/cp/rm/ls/mv】
    [Linux]监控外部用户登录及外部主机连接情况
    [Java SE]Unicode解码
  • 原文地址:https://www.cnblogs.com/sunnyeve/p/15589472.html
Copyright © 2011-2022 走看看