Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

函数里面的中断

比如说我们在函数里面想中断,不往下执行

methods:{
    fun1(){
        return;
        //不会往下执行
    }
}

但是如果函数里面再调用函数

methods:{
    fun1(){
        func2();
        //还是会往下执行
    },
    fun2(){
        return;
    }
}

我能想到的办法是throw

methods:{
    fun1(){
        func2();
        //不会会往下执行
    },
    fun2(){
        throw 'error';
    }
}

这种办法好不好,还有什么办法
我的应用场景是在vue的methods里面函数之间调用


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
fun1 () {
    if (this.func2()) return false
},
fun2 () {
    return false;
}

给函数返回值就行了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...