demo.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. 12、data强制刷新方法
  16. 13、数组添加元素
  17. 14、条件编译
  18. 15、组件传入当前对象
  19. 16、防止点击穿透
  20. 17、数组删除指定元素
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. // 此处为页面级,所以name值可选
  26. name: 'page',
  27. data() {
  28. return {
  29. }
  30. },
  31. onLoad() {
  32. },
  33. mounted() {
  34. // 2、
  35. // 将会得到父页面的this实例
  36. uni.$u.$parent.call(this, 'page')
  37. }
  38. methods: {
  39. demo() {
  40. // 1、
  41. // 300ms后触发回调
  42. uni.$u.sleep(300).then(() => {
  43. console.log('定时结束')
  44. })
  45. // 3、
  46. // <view class="throttle" @tap="$u.throttle(btnAClick, 500)">
  47. // uni.$u.throttle(this.toNext, 500)
  48. // <view class="debounce" @tap="$u.debounce(btnAClick, 500)">
  49. // uni.$u.debounce(this.toNext, 500)
  50. // 4、
  51. let b = uni.$u.deepClone(a);
  52. // 5、
  53. // 无参数
  54. uni.$u.route('/pages/components/empty/index');
  55. // 带参数
  56. uni.$u.route('/pages/goodSource/shippingDetails', {
  57. id: 1,
  58. });
  59. // 6、
  60. uni.$u.queryParams(this.data)
  61. // 7、
  62. uni.$u.test.idCard('110101199003070134')
  63. // 8、
  64. // default/error/success/loading
  65. // <u-toast ref="uToast"></u-toast>
  66. // this.$refs.uToast.show({
  67. // type: 'error',
  68. // message: "最多选择3个地区",
  69. // })
  70. // let params = {
  71. // type: 'success',
  72. // title: '成功主题(带图标)',
  73. // message: "庄生晓梦迷蝴蝶",
  74. // iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  75. // }
  76. // this.$refs.uToast.show({
  77. // ...params,
  78. // complete() {
  79. // params.url && uni.navigateTo({
  80. // url: params.url
  81. // })
  82. // }
  83. // })
  84. // uni.$u.toast('倒计时结束后再发送');
  85. // 9、
  86. // <u-modal :show="isShowAlert" :title="alertTitle" :content='alertContent' :closeOnClickOverlay='true' :showCancelButton='true' confirmColor='#22C572' @confirm="confirmClick" @close="cancelClick" @cancel="cancelClick"></u-modal>
  87. // confirmClick(){
  88. // this.isShowAlert = fasle
  89. // },
  90. // cancelClick(){
  91. // this.isShowAlert = false
  92. // },
  93. // 10、
  94. // this.$request.baseRequest('get', '/commonUser/loginVerifyCode', {
  95. // phone: that.model1.phone,
  96. // verifyCode: that.model1.code
  97. // }).then(res => {
  98. // })
  99. // .catch(res => {
  100. // uni.$u.toast( res.message);
  101. // });
  102. // 11、
  103. // uni.showLoading({
  104. // title: '登录中',
  105. // mask: true
  106. // })
  107. // 12、
  108. // _this.$forceUpdate()
  109. // 13、
  110. // 开头添加 unshift
  111. // 14、
  112. // #ifdef APP-PLUS
  113. // #endif
  114. // 15、$event
  115. // 16、@click.stop
  116. // 17、this.carList.splice(index,1)
  117. }
  118. }
  119. }
  120. </script>