import Throttle from '$utils/tool/throttle'; import user from "$config/user"; export default { data(){ return { collect:0 } }, watch:{ 'info.is_collect':function () { return this.setCollect(this.info.is_collect,false); } }, methods:{ // 触发更改关注 triggerFollow(){ return this.setCollect(this.collect?0:1,true); }, // 设置是否关注 setCollect(collect,update:boolean=true){ if (user.verificationLogin()) { if (this.info.room_background_id !== undefined) { if(this.collect !== collect){ this.collect = collect; if (this._collect === undefined) { this._collect = collect; } return this.triggerCollect(); } } } }, // 请求接口设置 triggerCollect(){ if (this._collect !== this.collect) { this._collect = this.collect; this.$request({ url: this._collect ? 'Usercollectroom/collect_room':'Usercollectroom/un_collect_room', data:{ rid: this.info.rid }, token:true }); } } }, created(){ this.triggerCollectThrottle = new Throttle({ call:this, first:false, handle:this.triggerCollect, delay:500 }); this.triggerCollect = this.triggerCollectThrottle.supper; }, beforeUnmount() { this.triggerCollectThrottle && this.triggerCollectThrottle.destroy(); } }