vue 关注已关注按钮切换


<view class="feature-info">
<view class="feature-list info-row">

  <text v-if="isFollow == 1" class="attention" @click="unsubscribe()">已关注</text>   <text v-if="isFollow == 0" class="attention" @click="subscribe()">关注</text>

</view> </view>
      data() {
            return {
                isFollow: 0,
            };
        unsubscribe() {
                new ShopService().unfollowCoach(this.id).then((data: any) => {
                    if (data.code == 1) {
                        uni.showToast({
                            title: data.msg,
                        });
                        this.isFollow = 0;
                    } else {
                        uni.showToast({
                            title: data.msg,
                        });
                    }
                }).catch((error: any) => {
                    uni.hideLoading()
                });
            },
            subscribe() {
                new ShopService().followCoach(this.id).then((data: any) => {
                    if (data.code == 1) {
                        uni.showToast({
                            title: data.msg,
                        });
                        this.isFollow = 1;
                    } else {
                        uni.showToast({
                            title: data.msg,
                        });
                    }
                }).catch((error: any) => {
                    uni.hideLoading()
                });
            },
shopservice.ts

// 关注教练 public followCoach(id: any):Promise<any> {//传id return super.post('/api.php/shop/Coach/coachSubscribe',{id: id}) } // 取消关注教练 public unfollowCoach(id: any):Promise<any> { return super.post('/api.php/shop/Coach/unsubscribe',{id: id}) }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM