@antdv/pro-utils
Version:
@antdv/pro-utils
32 lines (31 loc) • 779 B
JavaScript
import { createVNode as _createVNode } from "vue";
import { Result } from "ant-design-vue";
import { defineComponent, onErrorCaptured, ref } from "vue";
const ErrorBoundary = defineComponent({
name: "ErrorBoundary",
setup(_, {
slots
}) {
const hasError = ref(false);
const errorInfo = ref("");
onErrorCaptured((err) => {
hasError.value = true;
errorInfo.value = err.message;
});
return () => {
var _a;
if (hasError.value) {
return _createVNode(Result, {
"status": "error",
"title": "Something went wrong.",
"extra": errorInfo.value
}, null);
} else {
return (_a = slots.default) == null ? void 0 : _a.call(slots);
}
};
}
});
export {
ErrorBoundary
};