小程序获得input的值并传给下一个页面

wxml
<view class="cu-modal {{modalName==\'DialogModal1\'?\'show\':\'\'}}">
  <view class="cu-dialog">
    <view class="cu-bar bg-white justify-end">
      <view class="content">请输入比赛编号</view>
      
    </view>
    <view class="padding-xl">
      <input placeholder="比赛编号" name="id" bindinput=\'getInputValue\'></input>             获得这个Input的值
    </view>
    <view class="cu-bar bg-white justify-end">
      <view class="action">
        <button class="cu-btn line-green text-green" bindtap="hideModal">取消</button>
        <button class="cu-btn bg-green margin-left" bindtap="hideModal">加入评分</button>

      </view>
    </view>
  </view>
</view>


js:
data: {
    id:\'\'
  },
//获取id值,并赋值
  getInputValue:function(e){
    this.setData({
      id:e.detail
    })
    var id = this.data.id
  },
hideModal(e) {
    let that = this
    console.log(that.data.id.value)
    that.setData({
      modalName: null
    })
    wx.navigateTo({
      url: \'/pages/score/score?id=\'+ that.data.id.value      //传值格式
    })
  },


下一个页面onload接收
onLoad: function (options) {
    console.log(options)
    var that = this
    var id = options.id
    that.setData({  //前端向后端发送的数据
          id:this.id
      })
    
    wx.request({
      
      url: \'http://localhost/tp/public/wx/createscore\',    
      data: {  //前端向后端发送的数据
          id:options.id
      },
      header: {
        \'content-type\': \'application/json\' // 默认值
      },
      success(res) {
        //console.log(res)
        console.log(res.data)
        that.setData({
          name:res.data.name,
          score:res.data.score
        })
      },
      
    })
  },



<view class="center-text">{{name}}</view>



thinkphp
 public function createScore()
    {
        $param1 = Request::param(\'id\');
        return json(\think\facade\Db::name(\'score\')->where(\'id\', $param1)->find() );
        //var_dump(\think\facade\Db::name(\'score\')->where(\'id\', $param1)->find()  );
    }

{{uploading-image-296622.png(uploading…)}}

版权声明:本文为serendipity-my原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/serendipity-my/p/13731564.html