UNPKG

@slan-health/taro-vueuse

Version:

taro vue版本hooks

44 lines (43 loc) 1.17 kB
import { showLoading, hideLoading } from "@tarojs/taro"; function useLoading(initialOption) { const showLoadingAsync = (option = { title: "加载中...", mask: false }) => { return new Promise((resolve, reject) => { try { if (!option && !initialOption) { console.warn("please provide a option"); return reject(new Error("please provide a option")); } else { const options = Object.assign({}, initialOption || {}, option || {}); if (!options.title) { reject({ errMsg: "showLoading: fail" }); } else { showLoading({ ...options, success: resolve, fail: reject }).catch(reject); } } } catch (e) { reject(e); } }); }; const hideLoadingAsync = () => { return new Promise((resolve, reject) => { try { hideLoading({ success: resolve, fail: reject }); } catch (e) { reject(e); } }); }; return [showLoadingAsync, hideLoadingAsync]; } export { useLoading as default }; //# sourceMappingURL=index.js.map