小程序之校园交流平台
发布帖子
bindTextInput: function (e) { this.setData({ publishContent: e.detail.value }); }, bindTitleInput: function (e){ this.setData({ publishTitle: e.detail.value }) }
输入内容,然后获得内容
点击发送,发出request请求
//成功返回查看帖子页面 submitData: function(){ wx.request({ url: 'https://wei2014.cn/addMessage', data:{ title: this.data.publishTitle, // content: this.data.publishContent, name: "yunhu" }, success: function (res) { console.log(res.data) console.log(res.data.result) if(res.data.result == 'success') { wx.showToast({ title: "发送成功" }) wx.navigateTo({ url: '../main/main' }) } else{ wx.showToast({ title: "发送失败" }) } } }) },
点击我要发帖
<button class = "add" bindtap="publish" >我要发帖</button>
跳转页面
publish: function () { wx.navigateTo({ url: '../communityPublish/communityPublish' }) console.log(this.data.content) },
显示帖子
onShow: function () { //console.log("title:"+this.data.title) console.log("show") var that = this; wx.request({ url: 'https://wei2014.cn/getMessageList', //url: 'https://yunhu123.cn/', data: { page: 1 }, header: {}, method: "GET", dataType: "json", success: function (res) { that.setData({ content: res.data.messageList }); console.log("从服务器获取数据成功") console.log(that.data.content) }, fail: function (res) { console.log("从服务器获取数据失败") }, complete: function (res) { }, }) },
帖子内容过长只显示三行
text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; overflow: hidden; -webkit-box-orient: vertical;
点击部分内容显示完整的内容
获取点击的目标帖子的标题内容和名字,然后待参数传给allcontent页面。
showallcontent: function(e){ var nowtitle = e.currentTarget.dataset.title var nowname = e.currentTarget.dataset.name var nowcontent = e.currentTarget.dataset.content console.log(nowtitle) console.log(nowname) console.log(nowcontent) wx.navigateTo({ url: '../allcontent/allcontent?title='+nowtitle+'&name='+nowname+'&content='+nowcontent }) }
获取main页面传过来的数据
onLoad: function (options) { var that = this that.setData({ title: options.title, name: options.name, content: options.content }) console.log(that.data.title) console.log(that.data.name) console.log(that.data.content) },
显示出来
<view class = "csstitle">{{title}}</view> <text>{{name}}\n\n</text> <view class='csscontent'><text>{{content}}</text></view><view class = "csstitle">{{title}}</view> <text>{{name}}\n\n</text> <view class='csscontent'><text>{{content}}</text></view>