コードES6の方が良ければ、重複を避けるために構造を使用するのが良いでしょうか?どのように私はparamsと各機能のためのオプションを破壊するのですか?
他の機能で同じparams
とoptions
をどのように使用しますか?Class
?以下のような
例:
const params = [
title,
text,
confirm,
buttonConfirm || "Ok",
buttonCancel || "Cancel",
];
const options = {
title: params.title,
text: params.text,
confirmButtonText: params.buttonConfirm,
cancelButtonText: params.buttonCancel,
showCancelButton: Boolean(params.confirm),
};
class Alert {
success(...params) {
alertPlugin({
...options,
type: "success",
}).then(
() => params.confirm()
);
},
error(...params) {
alertPlugin({
...options,
type: "error",
}).then(
() => params.confirm()
);
},
warning(...params) {
alertPlugin({
...options,
type: "warning",
}).then(
() => params.confirm()
);
}
}
export default Alert;
そして、私はこのコードでメソッドを呼び出します。
this.$alert.success({
"Title custom",
"Description custom",
this.callbackSuccess,
"Yeah!",
"Noo!",
});
どのようにこれらのメソッドを呼び出す予定ですか? – ktilcu
オブジェクトのプロパティを配列に広げるためにスプレッド演算子を使うことはできません。別のオブジェクト、つまり '{... this.options}'になければなりません。オブジェクトの値を配列形式で取得する場合は、[Object.values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)を参照してください。 –
@ktilcu質問を編集 –