介绍

  • 文件中的方法都是常用方法,功能单一,使用时可以通过 Vue 调用。

    目录

  • popup 弹窗封装

  • storage 缓存封装

    详细

    popup

    封装:https://uniapp.dcloud.io/api/ui/prompt

showLoading 和 hideLoading

  • showLoading :显示 loading 窗
  • hideLoading :隐藏 loading 窗

    1. this.$u.showLoading('加载页面') // 打开一次 loading
    2. this.$u.showLoading('你好',1000) // 打开loading 并在 1000毫秒后关闭
    3. this.$u.hideLoading() // 关闭一次 loading
    4. this.$u.hideLoading(true) // 无论有没有loading 没结束,都强制关闭 loading

    参数

    showLoading
    | 参数 | 类型 | 是否必填 | 说明 | | —- | —- | —- | —- | | text | String | N | 提示内容 (默认:加载中) | | time | Number | N | 自动关闭时间(毫秒) | | config | Object | N | 其他配置详情:https://uniapp.dcloud.io/api/ui/prompt?id=showloading |

hideLoading
参数 类型 是否必填 说明
enforce Boolean N 是否强制关闭

解决

  • 通过记录调用 showLoading 次数,解决多次调用 showLoading 闪烁问题。

    showToast 和 hideToast

  • showToast 提示

  • hideToast 隐藏 showToast

    1. this.$u.showToast('标题',1000,'none',{}).then(res=>{
    2. console.log('弹窗关闭')
    3. }
    4. this.$u.hideToast(); // 关闭弹窗 并执行弹窗关闭后事件

    参数

    showToast
    | 参数 | 类型 | 是否必填 | 说明 | | —- | —- | —- | —- | | title | String | Y | 提示内容 | | duration | Int | N | 提示的延迟时间,单位毫秒,默认:1500 | | icon | String | N | ['success','loading','none'] 之一 或 图片url | | config | Object | N | 其他配置详情:https://uniapp.dcloud.io/api/ui/prompt?id=showtoast |

hideToast
参数 类型 是否必填 说明
can Boolean N 关闭后是否执行 toast 结束事件

返回

  • 返回一个 Promise

    • resolve :延时执行结束后
    • reject :失败回调

      showModal , alert , confirm

  • showModal:对话框,

  • alert:模拟 alert
  • confirm: 模拟 confirm

    ```javascript this.$u.showModal({title:’name’}).then(res=>{ console.log(‘确定’) }).catch(res=>{ console.log(‘取消’) })

this.$u.alert(‘name’,’content’).then(res=>{ console.log(‘确定’) })

this.$u.confirm(‘name’,’content’).then(res=>{ console.log(‘点击确定’) },res=>{ console.log(‘点击取消’) })

  1. <a name="a0ACe"></a>
  2. #### 参数
  3. <a name="wyOhe"></a>
  4. ##### showModal
  5. | 参数 | 类型 | 是否必填 | 说明 |
  6. | --- | --- | --- | --- |
  7. | config | Object | Y | 所有配置内容 : [https://uniapp.dcloud.io/api/ui/prompt?id=showmodal](https://uniapp.dcloud.io/api/ui/prompt?id=showmodal) |
  8. <a name="M0rkK"></a>
  9. ##### alert 和 confirm
  10. | 参数 | 类型 | 是否必填 | 说明 |
  11. | --- | --- | --- | --- |
  12. | title | string | Y | 标题 |
  13. | content | string | N | 内容 |
  14. | config | Object | N | 所有配置内容 : [https://uniapp.dcloud.io/api/ui/prompt?id=showmodal](https://uniapp.dcloud.io/api/ui/prompt?id=showmodal) |
  15. <a name="YUXKe"></a>
  16. #### 返回
  17. - 返回一个 `Promise`
  18. - `resolve` 点击确定
  19. - `reject` 点击取消
  20. <a name="0vWqG"></a>
  21. ### showActionSheet
  22. - 从底部向上弹出操作菜单
  23. ```javascript
  24. this.$u.showActionSheet(['选项1','选项2','选项3'],'#0000ff').then(res=>{
  25. console.log('选择了第'+(res.tapIndex+1))
  26. }).catch(
  27. res=>{
  28. console.log('没选择')
  29. }
  30. )

参数

参数 类型 是否必填 说明
itemList Array Y 按钮的文字数组
itemColor string N 按钮的文字颜色,字符串格式,默认为”#000000”

返回

  • 返回一个 Promise

    • resolve 点击选项, tapIndex 表示 数组的 index
    • reject 取消

      storage

      set 和 setSync

  • set : 异步存

  • setSync : 同步存

    ```javascript // 普通设置 this.$Storage.set(‘name’,’123’).then(res=>{ console.log(res) })

this.$Storage.setSync(‘Jon’,{age:10,name:’乔恩’}) // 设置数据并设置过期时间

this.$Storage.set(‘name’,’123’,(new Date().getTime())).then(res=>{ console.log(res) })

this.$Storage.setSync(‘Jon’,{age:10,name:’乔恩’},(new Date().getTime()))

  1. <a name="P1nUk"></a>
  2. #### 参数
  3. | 参数 | 类型 | 是否必填 | 说明 |
  4. | --- | --- | --- | --- |
  5. | keyName | String | Y | key |
  6. | value | | Y | 存储值 |
  7. | time | Number | N | 过期时间,(毫秒时间戳)仅在使用指定的 `getSync` 取时才游有用 |
  8. <a name="vpMu7"></a>
  9. ### getSync
  10. - 同步取
  11. <a name="ZVhtt"></a>
  12. #### 例
  13. ```javascript
  14. let d = this.$Storage.getSync('Jon')

参数

参数 类型 是否必填 说明
keyName String Y key

remove

  • 同步删

    1. let d = this.$Storage.getSync('Jon')

    参数

    | 参数 | 类型 | 是否必填 | 说明 | | —- | —- | —- | —- | | keyName | String | Y | key |