代码变漂亮!

让你的代码变漂亮吧

多层嵌套
this.axios.get(url).then(res=>{
    if(res.status){
        if(res.status==1){
            this.isShow = true
        }
    }
})

//魔法棒======================>
this.axios.get(url).then(res=>{
    res.status && res.status==1 && (this.isShow=true)
})
三目运算符
if(this.val==1){
   Toast('提交成功')
}else{
   Toast('提交失败')
}
//魔法棒======================>
let msg = this.val==1?'提交成功':'提交失败';
Toast(msg);
赋值
if(this.default){ 
    this.index = this.default 
}else{ 
    this.index = 1 
} 
//魔法棒======================>
this.index = this.default || 1
多种情况弹窗处理
showMsg(type,msg){//type=1/2/3/4
    let that = this;
    if(type=='1'){
       this.$dialog.confirm({
            title:'提示',
            cancelButtonText:'再来一次',
            confirmButtonText:'aaaaa',
            showCancelButton:false,
            message:msg,
        }).then(()=>{
            this.aaa().call(that)
        }).catch(()=>{
            this.isShow = true
        })
    }
    if(type=='2'){
       return
    }
    if(type=='3'){
       this.$dialog.confirm({
            title:'提示',
            cancelButtonText:'再来一次',
            confirmButtonText:'ccccc',
            showCancelButton:true,
            message:msg,
        }).then(()=>{
            this.ccc().call(that)
        }).catch(()=>{
            this.isShow = true
        })
    }
    if(type=='4'){
       this.$dialog.confirm({
            title:'提示',
            cancelButtonText:'再来一次',
            confirmButtonText:'ddddd',
            showCancelButton:false,
            message:msg,
        }).then(()=>{
            this.ddd().call(that)
        }).catch(()=>{
            this.isShow = true
        })
    }
}
//魔法棒======================>
showMsg(type,msg){//type=1/2/3/4
    if(type==='2')return
    let that = this;
    let typeText = newMap([
        [1,["aaaaa"],false,()=>this.aaa()],
        [3,["ccccc"],false,()=>this.ccc()],
        [4,["ddddd"],false,()=>this.ddd()],
    ])
    this.$dialog.confirm({
        title:'提示',
        cancelButtonText:'再来一次',
        confirmButtonText:typeText.get(type)[0],
        showCancelButton:typeText.get(type)[1],
        message:msg,
    }).then(()=>{
        typeText.get(type)[2].call(that)
    }).catch(()=>{
        this.isShow = true
    })
}
参数默认值
function newParams(name){
    const userName = name || '用户'
}
//魔法棒======================>(参数少的情况)
function newParams(userName='用户'){
    //...
}
操作数组
var addItem = (arr,item)=>{
    arr.push({item,date: Date.now()})
}
//魔法棒======================>
var addItem = (arr,item)=>{
    return [...arr, {item,date: Date.now()} ]
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值