Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小程序增加点赞功能的方法 #71

Closed
hgmsq opened this issue Jul 5, 2020 · 1 comment
Closed

小程序增加点赞功能的方法 #71

hgmsq opened this issue Jul 5, 2020 · 1 comment

Comments

@hgmsq
Copy link

hgmsq commented Jul 5, 2020

只需要在post.js 增加以下方法就可以了

//点赞功能
Likes: function () {
    var that = this;
    var urlLikeList = app.globalData.url + '/api/content/posts/'+that.data.postId+'/likes';
    var token = app.globalData.token;
    var params = {            
    };
    //@todo 网络请求API数据
    request.requestPostApi(urlLikeList, token, params, this, this.successSendLike, this.failSendLike);  
},
// 点赞成功回调
successSendLike: function (res, selfObj) {
    var that = this;        
    wx.showToast({
        title: '感谢你的点赞!',
        icon: 'none',
        duration: 2000
    });
    // 设置点赞数+1
    var likes = Number(parseInt(that.data.postLikes) + 1);   
    console.log(likes);
    that.setData({
         postLikes: likes       
    })
},
//点赞失败回调
failSendLike: function (res, selfObj) {
    wx.showToast({
        title: '点赞失败,请联系作者!',
        icon: 'none',
        duration: 2000
    })
},

小程序名称:IT技术分享社区
IT技术分享社区
gh_32334eb097cd_430

@sav7ng
Copy link
Owner

sav7ng commented Jul 6, 2020

感谢贡献代码~

@sav7ng sav7ng closed this as completed Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants