(5) [Interlude] Solving the problem of error reporting in the index.js file regarding parameters that implicitly have the "any" type

When learning form components, I added the following code based on online tutorials.

1. Add the following to index.wxml.

<form bindsubmit="formSubmit">
  <view class="section section_gap">
    <view class="section__title">slider</view>
    <slider name="slider" show-value ></slider>
  </view>
  <view class="btn-area">
    <button formType="submit">Submit</button>
  </view>
</form>

2. Add the following to index.ts.

  formSubmit: function (e) {
    console.log('form发生了submit事件,携带数据为:', e.detail.value)
    this.setData({
      allValue:e.detail.value
    })
  }
})

At this time, the compilation system reports the following error.

3. Problem solution: Modify "e" in function to "e:any" in the index.ts file.

  formSubmit: function (e:any) {
    console.log('form发生了submit事件,携带数据为:', e.detail.value)
    this.setData({
      allValue:e.detail.value
    })
  }
})

If it is an index.js file, just use function(e).

Guess you like

Origin blog.csdn.net/qq_38250687/article/details/130644001