1. <template>
    2. <view>
    3. <view>
    4. <form @submit="formSubmit" @reset="formReset">
    5. <view class="uni-form-item uni-column">
    6. <view class="title">switch</view>
    7. <view>
    8. <switch name="switch" />
    9. </view>
    10. </view>
    11. <view class="uni-form-item uni-column">
    12. <view class="title">radio</view>
    13. <radio-group name="radio">
    14. <label>
    15. <radio value="radio1" /><text>选项一</text>
    16. </label>
    17. <label>
    18. <radio value="radio2" /><text>选项二</text>
    19. </label>
    20. </radio-group>
    21. </view>
    22. <view class="uni-form-item uni-column">
    23. <view class="title">checkbox</view>
    24. <checkbox-group name="checkbox">
    25. <label>
    26. <checkbox value="checkbox1" /><text>选项一</text>
    27. </label>
    28. <label>
    29. <checkbox value="checkbox2" /><text>选项二</text>
    30. </label>
    31. </checkbox-group>
    32. </view>
    33. <view class="uni-form-item uni-column">
    34. <view class="title">slider</view>
    35. <slider value="50" name="slider" show-value></slider>
    36. </view>
    37. <view class="uni-form-item uni-column">
    38. <view class="title">input</view>
    39. <input class="uni-input" name="input" placeholder="这是一个输入框" />
    40. </view>
    41. <view class="uni-btn-v">
    42. <button form-type="submit">Submit</button>
    43. <button type="default" form-type="reset">Reset</button>
    44. </view>
    45. </form>
    46. </view>
    47. </view>
    48. </template>
    49. <script>
    50. export default {
    51. data() {
    52. return {
    53. counter: 0,
    54. }
    55. },
    56. onLoad() {
    57. },
    58. methods: {
    59. formSubmit: function(e) {
    60. console.log('form发生了submit事件,携带数据为:' + JSON.stringify(e.detail.value))
    61. var formdata = e.detail.value
    62. uni.showModal({
    63. content: '表单数据内容:' + JSON.stringify(formdata),
    64. showCancel: false
    65. });
    66. },
    67. formReset: function(e) {
    68. console.log('清空数据')
    69. }
    70. },
    71. }
    72. </script>

    效果图:
    image.png