团队作业-冲刺二(11)

收藏的模板

 1 <!--被收藏的次数-->
 2 <li class="like">
 3     <span class="iconfont">&#xe663;</span>
 4     {{ blogData.f_collection_sum }}
 5 </li>
 6 <!--是否被收藏的样式-->
 7 <li class="like" v-model="key">
 8     <span class="iconfont">
 9         <i v-if = "!isCollection" class="el-icon-star-off" :key="0" @click="onCollection"></i>
10         <i v-else class="el-icon-star-on" :key="1" @click="onCollection"></i>
11     </span>
12 </li>
13 
14 onCollection(){
15     if(this.isCollection){
16         //取消收藏
17         let params = {};
18         let f_special_document_id = localStorage.getItem("f_special_document_id");
19         params.f_special_document={
20             f_special_document_id:f_special_document_id,
21         };
22         delSort(params).then(response => {
23             if (response.data.httpStatus === 200) {
24                 this.$notify({
25                     title: "成功",
26                     message: "取消收藏",
27                     type: "success",
28                     offset: 100
29                 });
30                 this.key = 0; //使用key值区分两种状态的样式
31                 this.isCollection = false; //待收藏状态
32                 this.blogData.f_collection_sum -= 1; 收藏数减一            
33              } else {
34                 this.$notify.error({
35                     title: "错误",
36                     message: response.data.message,
37                     offset: 100
38                 });
39             }
40         });
41     }else{
42         //新增收藏
43         let params = {};
44         let f_special_document_id = localStorage.getItem("f_special_document_id");
45         let f_special_document_name = localStorage.getItem("f_special_document_name");
46         params.f_special_document={
47             f_special_document_id:f_special_document_id,
48             f_special_document_name:f_special_document_name,
49         }
50         addSort(params).then(response => {
51             if (response.data.httpStatus === 200) {
52                 this.$notify({
53                     title: "成功",
54                     message: "收藏成功",
55                     type: "success",
56                     offset: 100
57                 });
58                 this.key = 1;
59                 this.isCollection = true;
60                 this.blogData.f_collection_sum += 1;
61             } else {
62                 this.$notify.error({
63                     title: "错误",
64                     message: response.data.message,
65                     offset: 100
66                 });
67             }
68         })
69     }
70 },

 

 

posted @ 2023-05-23 20:09  旺旺大菠萝  阅读(9)  评论(0)    收藏  举报