vue写后台管理系统,有个需求将所有的$message消息提示换成确认框来增强消息提示效果,遇到嵌套过多的情况,出现某些问题

DepartList.vue:573 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$confirm') at eval (DepartList.vue:573:1)

正常情况下是

this.$confirm({

title: '消息提示',

content: h => <div style="color:red;">请选择一条记录!</div>,

onOk() {

console.log('OK');

},

onCancel() {

console.log('Cancel');

},

});

这样就ok,其他几种提示情况呢,比如

this.$confirm({

title: '消息提示',

content: h => <div style="color:red;">{res.message}</div>,

onOk:()=> {

console.log('OK');

},

onCancel:()=> {

console.log('Cancel');

},

});

渲染消息的情况,变量这么渲染

报错的那种场景是,有一个确认框了,比如删除,确定删除吗?这是一个确认框,当删除成功以后显示删除成功又是一个确认框来提示消息,嵌套层级过高,this 的上下文没有正确绑定到 Vue 实例上。为了确保 this 的上下文正确,可以使用箭头函数来定义回调函数,这样可以保留外部 this 的上下文。

简单小问题,开发随记%%%%%%%%%%%%

相关推荐
fthux1 小时前
RenoPit 能为普通业主做什么?看懂图纸、审查合同,提前发现装修坑
javascript·人工智能·ai·开源·github·chrome扩展·open source·edge扩展·firefox扩展
仿生狮子2 小时前
✂️ Nuxt 最简单的字体裁剪工具:Fontize
javascript·vue.js·nuxt.js
石小石Orz5 小时前
我发现了开发者AI产品营收的新方向
前端·虚拟现实
老马识途2.05 小时前
关于跨域问题的总结
java·前端
魔力女仆5 小时前
分享一个 JS 鼠标跟随贪吃蛇背景库
开发语言·javascript·计算机外设
别惊醒渔人7 小时前
Vue3 Diff 优化:最长递增子序列 LIS
前端·javascript·vue.js
颜酱7 小时前
07 | 把字段与指标同步到 Qdrant(生成阶段)
前端·人工智能·后端
用户059540174467 小时前
把AI长期记忆测试从手动验证换成pytest,2天揪出11个隐藏Bug
前端·css
Larcher7 小时前
从“加载模型”界面到端侧推理:拆解一个 React + WebGPU 大模型 Demo
javascript·后端
Larcher8 小时前
从状态快照到惰性初始化:读懂 React useState 的三个关键场景
javascript·人工智能·后端