1 分析:
 2  需要动态的向数据库中插入数据,既然要进行添加操作,就会触发一个点击的事件,所以我们的第一步就是要先绑定事件
 3  向服务器进行请求接口操作,请求的方法为 ‘POST’
 4  最后就是在methods中写函数
 5 操作:
 6 (1)绑定事件
 7 <view @tap="saveOpportunity()">保存</view>

8 (2)表单进行数据的双向绑定 9 <input type="text" v-model="opportunity.addr" > //你的字段的名称,接口文档的字段名称如果是必填项,这边一定要进行绑定,一般情况下,我们这里会都给它添加上
10 (3)data中添加一个对象 opportunity 11 Opportunity{}
12 (4)methods中写方法 13 saveOpportunity(){ 14 uni.request({ 15 method:'POST', 16 data:this.opportunity, //当前的对象 17 url: `${this.$serverUrl}/opportunity/`, //封装后的接口的地址 18 success(res) { //回调函数 19 console.log(res) 20 } 21 }) 22 }

 

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-04-26
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-28
  • 2022-02-12
  • 2022-12-23
  • 2021-04-21
  • 2021-10-06
  • 2021-10-27
  • 2021-08-17
相关资源
相似解决方案