submit-btn.vue 891 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <view class="submit-btn" @tap="$tools.throttle(submit)">
  3. <slot name="btns" v-bind:isSubmitted="isSubmitted"></slot>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. isOnce:{
  10. type:Boolean,
  11. default:true
  12. }
  13. },
  14. data() {
  15. return {
  16. isSubmitted:false,
  17. }
  18. },
  19. beforeDestroy(){
  20. if(this.submitTimer){
  21. // console.log("beforeDestroy 销毁 this.timer--")
  22. clearTimeout(this.submitTimer);
  23. this.submitTimer = null;
  24. }
  25. },
  26. methods:{
  27. submit(){
  28. if(this.isSubmitted){
  29. return;
  30. }
  31. this.$emit("submit")
  32. },
  33. chgeStatus(){
  34. this.isSubmitted = true;
  35. if(!this.isOnce){
  36. this.submitTimer = setTimeout(()=>{
  37. // console.log("定时到---")
  38. this.isSubmitted = false;
  39. },3000)
  40. }
  41. },
  42. }
  43. }
  44. </script>
  45. <style lang="scss" scoped>
  46. // .submit-btn{
  47. // opacity: 0.6;
  48. // }
  49. </style>