Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

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

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

我能想到的办法是throw

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

fun1 () {
    if (this.func2()) return false
},
fun2 () {
    return false;
}

给函数返回值就行了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...