vibrate.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap">
  5. <button class="uni-button" type="primary" @click="longshock">长震动</button>
  6. <button class="uni-button" @click="shortshock">短震动</button>
  7. <view class="uni-tips">
  8. <view>Tips</view>
  9. <view class="uni-tips-text">iOS上只有长震动,没有短震动</view>
  10. <view class="uni-tips-text">iOS上需要手机设置“打开响铃时震动”或“静音时震动”,否则无法震动</view>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. title: 'vibrateLong/vibrateShort'
  20. };
  21. },
  22. onLoad() {},
  23. methods: {
  24. longshock() {
  25. uni.vibrateLong({
  26. success: function() {
  27. console.log('success');
  28. }
  29. });
  30. },
  31. shortshock() {
  32. uni.vibrateShort({
  33. success: function() {
  34. console.log('success');
  35. }
  36. });
  37. }
  38. }
  39. };
  40. </script>
  41. <style>
  42. .uni-padding-wrap {
  43. margin-top: 50rpx 0;
  44. }
  45. .uni-button {
  46. margin: 30rpx 0;
  47. }
  48. .uni-tips {
  49. color: #666;
  50. font-size: 30rpx;
  51. }
  52. .uni-tips-text {
  53. margin-top: 15rpx;
  54. line-height: 1.2;
  55. font-size: 24rpx;
  56. }
  57. </style>