小程序之校园交流平台

  1. 发布帖子

      bindTextInput: function (e) {
        this.setData({
          publishContent: e.detail.value
        });
      },
      bindTitleInput: function (e){
        this.setData({
          publishTitle: e.detail.value
        })
      }

    输入内容,然后获得内容

  2. 点击发送,发出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: "发送失败"
              })
            }
          }
        })
      },
  3. 点击我要发帖

    <button class = "add" bindtap="publish" >我要发帖</button>
    

    跳转页面

      publish: function () {
        wx.navigateTo({
          url: '../communityPublish/communityPublish'
        })
        console.log(this.data.content)
      },
  4. 显示帖子

      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) { },
        })
      },
  5. 帖子内容过长只显示三行

      text-overflow: ellipsis; 
      display: -webkit-box;  
      -webkit-line-clamp: 3;  
      overflow: hidden;
      -webkit-box-orient: vertical; 
  6. 点击部分内容显示完整的内容

    获取点击的目标帖子的标题内容和名字,然后待参数传给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
        })
      }
  7. 获取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)
      },
  8. 显示出来

    <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>
全部评论

相关推荐

头像
09-21 09:55
门头沟学院 Java
想玩飞盘的我刷牛客:不给自己发个offer?
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务