箭头函数可以替换let _this = this

博客提及代码‘let _this = this’,并指出箭头函数明显比‘let _this = this’简单得多,体现了箭头函数在代码编写上的优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

let _this = this

let _this = this;
            _this.$axios.get("https://jsonplaceholder.typicode.com/posts")
                .then(response => {
//                    console.log(response);
                    _this.blogs = response.data.slice(0, 15);

                })

箭头函数

.then(response => {
                        console.log(response);
                        this.submitShow = true
                    })

明显箭头函数比let _this = this简单得多

/提交表单 submit(formName){ let that = this; that.$refs[formName].validate((valid) => { if (valid) { //检查表单数据是否有变化 if (!this.isFormChanged()){ that.$message({ showClose: true, message:'您未做出任何改变,无需保存!', type: 'warning', }); return; } //检查主气象站设置 if (that.ruleform.main_flag===1 && that.$store.getters.editid == '){ //新增模式才做特殊检验 let params = { param: JSON.stringify({ substid: that.global.getSession('substid'), }), }; that.$axios.post('/isps/envmonitor/getmainnum', that.$qs.stringify(params)) .then(function (data) { let json = data.data; if (json.code === 0) { // 请求成功 let count = json.data?.envnum?.count ?? 0; console.log('json',json) if (count = 0){ //当前没有主气象站 或者当前修改的就是主气象站 that.save( ); } else { // 当前已有主气象站,提示用户手动去掉 that.$message.error('只允许有一个主气象站,请先取消已有的主气象站再配置!'); } else { that.$message.error(json.msg ||'查询主气象站失败!'); } }) .catch(function (error){ that.$message.error('查询主气象站失败!'); });else if (that.ruleForm.main_flag === 1 && that.$store.getters.editid != ''){ this.$confirm('此操作将会替换原有的主气象站配置,是否继续?','警告',{ confirmButtonText:“确定' cancelButtonText:‘取消’, type:'warning' }).then(() => { //用户点击了“确定”按钮后的逻辑处理 saveMainStation(); // 假设这里调用保存新主气象站的函数 this.$message.success('设置成功!'); }).catch(() => { // 用户点击了“取消”按钮后的逻辑处理 this.$message.info('已取消操作'); }); }else { // 没有开启主气象站,直接提交 that.save(); } }else { return false; } 80.195 }); },为什么提示没生效
最新发布
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值