在common下新建fun.js
// 不含icon提示框
const toast = str => {
return new Promise((resolve, reject) => {
uni.showToast({
title: str,
icon: "none",
duration: 2000,
success: () => {
setTimeout(() => {
resolve
}, 2000)
}
})
})
};
// 成功提示框
const successToast = str => {
return new Promise((resolve, reject) => {
uni.showToast({
title: str,
icon: "success",
duration: 2000,
success: () => {
setTimeout(() => {
resolve()
}, 2000)
}
})
})
};
// loading
const showLoading = () => {
return new Promise((resolve, reject) => {
uni.showLoading({
success: () => {
resolve()
}
})
})
};
// tipLoading ==>提示loading
const tipLoading = str => {
return new Promise((resolve, reject) => {
uni.showLoading({
title: str,
success: () => {
resolve()
}
})
})
};
// 隐藏loading
const hideLoading = () => {
return new Promise((resolve, reject) => {
uni.hideLoading({
success: () => {
resolve()
}
})
})
};
export default {
toast: toast,
successToast: successToast,
showLoading: showLoading,
tipLoading: tipLoading,
hideLoading: hideLoading,
}
在main.js中全局引入并使用
import $ from 'common/fun.js'
Vue.prototype.$ = $
在页面调用
t.$.toast("提示消息");
t.$.successToast('成功提示消息');
t.$.showLoading();
t.$.tipLiading("提示loading");
t.$.hideLoading();