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}) }
原文地址:https://www.cnblogs.com/lsongyang/p/13539504.html