detail.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. (function(){
  2. //点赞
  3. $("body").on("click", ".dianzan .like", function(){
  4. if($(this).hasClass("hasDian")){
  5. alertInfo("您已经给该信息点过赞!");
  6. }else{
  7. var infoId = $(this).attr("data-id");
  8. $.get("/article/like", {id: infoId}, function(res){
  9. if(res.code === 0){
  10. console.log("点赞成功!");
  11. $(".like").text("赞" + (parseInt($(".like").attr("data-count"))+1)).addClass("hasDian");
  12. } else {
  13. alertInfo(res.msg);
  14. }
  15. });
  16. }
  17. });
  18. }());
  19. //相关阅读
  20. var articleRelated = new Vue({
  21. el: "#articleRelated",
  22. data: {
  23. infoId: $("#articleId").val()?$("#articleId").val()*1:0,
  24. relatedList: []
  25. },
  26. methods: {
  27. getRelatedList: function () {
  28. var _self = this;
  29. if(this.infoId ===0){return;}
  30. $.getJSON("/article/related",{id: this.infoId}).done(function (r) {
  31. if (r.code === 0 && r.data) {
  32. _self.relatedList = r.data;
  33. }
  34. });
  35. },
  36. },
  37. created: function () {
  38. this.infoId = $("#articleId").val() ? $("#articleId").val()*1 : 0;
  39. // 获取相关阅读
  40. this.getRelatedList();
  41. },
  42. mounted: function () {
  43. var _self = this;
  44. }
  45. });