Vue.js 中的可选参数

abu*_*abu 4 javascript vuejs2

我在vuejs中有以下方法

methods: {
    show () {
    }
}
Run Code Online (Sandbox Code Playgroud)

在这个show()方法中,我经常想传递参数,当我将其称为 HTML 时,我通常不想传递参数。喜欢show (obj)show ()

我怎样才能做到这一点 ?

谢谢

con*_*exo 6

methods: {
    show (obj) {
        if(obj) {
            // code to be executed if obj was passed
        } else {
            // code to be executed if no obj was passed
        }
        // code to be executed regardless 
    }
}
Run Code Online (Sandbox Code Playgroud)