prototype.js 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import Vue from "vue";
  2. // 查找元素信息
  3. Vue.prototype.$createQuery = (query, arg) => {
  4. return new Promise((resolve) => {
  5. if (arg) {
  6. uni
  7. .createSelectorQuery()
  8. .in(arg)
  9. .select(`${query}`)
  10. .boundingClientRect((res) => {
  11. resolve(res);
  12. }).exec();
  13. } else {
  14. uni
  15. .createSelectorQuery()
  16. .select(`${query}`)
  17. .boundingClientRect((res) => {
  18. resolve(res);
  19. }).exec();
  20. }
  21. });
  22. };
  23. // toast提示
  24. Vue.prototype.$showToast = (params) => {
  25. uni.showToast({
  26. title: params.title,
  27. mask: params.mask === false ? false : true,
  28. icon: params.icon || 'none',
  29. duration: params.duration || 2000
  30. })
  31. }
  32. // loading加载
  33. Vue.prototype.$showLoading = (params) => {
  34. uni.showLoading({
  35. mask: (params && params.mask === false) ? false : true
  36. })
  37. }
  38. // 获取存储-getStorageSync
  39. Vue.prototype.$getSS = (name) => {
  40. return uni.getStorageSync(name)
  41. }
  42. // 设置存储-getStorageSync
  43. Vue.prototype.$setSS = (name, value) => {
  44. uni.setStorageSync(name, value)
  45. }