demo.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="content">
  3. 常用
  4. 1、延时一定时间进行回调
  5. 2、获取父组件this
  6. 3、节流防抖
  7. 4、对象克隆
  8. 5、路由跳转
  9. 6、对象修改为地址栏传参
  10. 7、常用规则校验
  11. 8、toast消息提示
  12. 9、弹框提示
  13. 10、请求方法
  14. 11、loading
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. // 此处为页面级,所以name值可选
  20. name: 'page',
  21. data() {
  22. return {
  23. }
  24. },
  25. onLoad() {
  26. },
  27. mounted() {
  28. // 2、
  29. // 将会得到父页面的this实例
  30. uni.$u.$parent.call(this, 'page')
  31. }
  32. methods: {
  33. demo() {
  34. // 1、
  35. // 300ms后触发回调
  36. uni.$u.sleep(300).then(() => {
  37. console.log('定时结束')
  38. })
  39. // 3、
  40. // <view class="throttle" @tap="$u.throttle(btnAClick, 500)">
  41. // uni.$u.throttle(this.toNext, 500)
  42. // <view class="debounce" @tap="$u.debounce(btnAClick, 500)">
  43. // uni.$u.debounce(this.toNext, 500)
  44. // 4、
  45. let b = uni.$u.deepClone(a);
  46. // 5、
  47. // 无参数
  48. uni.$u.route('/pages/components/empty/index');
  49. // 带参数
  50. uni.$u.route('/pages/goodSource/shippingDetails', {
  51. id: 1,
  52. });
  53. // 6、
  54. uni.$u.queryParams(this.data)
  55. // 7、
  56. uni.$u.test.idCard('110101199003070134')
  57. // 8、
  58. // default/error/success/loading
  59. // <u-toast ref="uToast"></u-toast>
  60. // let params = {
  61. // type: 'success',
  62. // title: '成功主题(带图标)',
  63. // message: "庄生晓梦迷蝴蝶",
  64. // iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  65. // }
  66. // this.$refs.uToast.show({
  67. // ...params,
  68. // complete() {
  69. // params.url && uni.navigateTo({
  70. // url: params.url
  71. // })
  72. // }
  73. // })
  74. // uni.$u.toast('倒计时结束后再发送');
  75. // 9、
  76. // <u-modal :show="isShowAlert" :title="alertTitle" :content='alertContent' :closeOnClickOverlay='true' :showCancelButton='true' confirmColor='#22C572' @confirm="confirmClick" @close="cancelClick" @cancel="cancelClick"></u-modal>
  77. // 10、
  78. // that.$request.baseRequest('get', '/commonUser/loginVerifyCode', {
  79. // phone: that.model1.phone,
  80. // verifyCode: that.model1.code
  81. // }).then(res => {
  82. // })
  83. // .catch(res => {
  84. // uni.showToast({
  85. // title: res.message,
  86. // icon: 'none',
  87. // duration: 2000
  88. // })
  89. // });
  90. // 11、
  91. // uni.showLoading({
  92. // title: '登录中',
  93. // mask: true
  94. // })
  95. }
  96. }
  97. }
  98. </script>