wxml:
<textarea class="input" bindinput=‘bindContent‘ value="" placeholder="请填写评论内容 "></textarea>
<button class=‘button show-button‘ bindtap="Submit" data-item_data1=‘{{item_data1}}‘ id="vid">发送</button>
js:
var ComContent = ‘‘
var CommentList = ‘[]‘
var app = getApp()
Page({
/**
*
*/
data: {
CommentList: [{}],
bindContent: null,
ComContent: ‘‘,
input: ‘‘,
},
bindContent: function(e) {
console.log(e)
//取值的时候要先打印e,看里面有什么,就怎么取
ComContent = e.detail.value
// 先给ComContent赋值再放到AppData里面
// ComContent = this.data.CommentList
this.setData({
focus: true,
ComContent: ComContent,
})
console.log("输入的内容是:" + ComContent)
},
wx.request({
url: ‘ ‘, //网络请求地址
method: ‘GET‘, //网络请求方式 : GET或者POST 。根据接口文档写
data: data, //把创建的data传给后端
header: { //请求头
‘content-type‘: ‘Submit‘
},
success: function(res) {
//请求成功以后后端返回给你的数据 res
console.log(res.ComContent)
that.bindContent.ComContent = null
wx.showToast({
title: ‘评论提交成功‘,
icon: ‘success‘,
duration: 2000,
ComContent: null
})
fail: res =>
wx.showToast({
title: ‘网络不好哟‘,
duration: 3000
})
}
that.setData({
focus: false,
CommentList: res.data.data
})
// 提交成功后返回上页
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
wx.navigateBack({
delta: 1,
})
},
})
},