yingyangdetail.vue 2.6 KB
<template>
  <div class="containerbox">
    <div class="sharetop flextwo" @click="back">
      <div class="leftrow">
        <img src="../../../assets/leftrow.png" alt />
      </div>
      <div class="sharemiddle">图文类</div>
      <div class="flexone" @click.stop="collect">
        <div class="sharebtn" style="margin-right:0.5rem;width:0.4rem;height:0.4rem">
          <img src="../../../assets/nostar.png" alt v-if="yingyangdetail.is_favorite==0" />
          <img src="../../../assets/star.png" alt v-else />
        </div>
        <div class="sharebtn">
          <img src="../../../assets/sharebtn.png" alt />
        </div>
      </div>
    </div>
    <div class="yingyangbox">
      <div class="yingyangtitle">{{yingyangdetail.title}}</div>
      <div class="yingyangcontent" v-html="yingyangdetail.content"></div>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
  data() {
    return {
      id: '',
      yingyangdetail: '',
    }
  },
  created() {
    this.id = this.$route.query.id;
  },
  methods: {
    back() {
      this.$router.go(-1)
    },
    getdetail() {
      let that = this;
      var url = "/api/index/knowledge_detail";
      let param = {
        knowledge_id: that.id
      };

      that.$axios
        .post(url, param)
        .then(function (res) {
          console.log(res);
          that.yingyangdetail = res.data.knowledge

        })
        .catch(function (err) {
          console.log(err);
        });
    },
    collect() {
      let that = this;
      var url = "/api/user/favorite";
      let param = {
        type: 1,
        favorite_id: that.id
      };

      that.$axios
        .post(url, param)
        .then(function (res) {
          console.log(res);
          if (that.yingyangdetail.is_favorite == 0) {
            Toast('收藏成功')
            that.yingyangdetail.is_favorite = 1;
            that.yingyangdetailt = that.yingyangdetail
          } else {
            Toast('取消收藏成功')
            that.yingyangdetail.is_favorite = 0;
            that.yingyangdetail = that.yingyangdetail
          }

        })
        .catch(function (err) {
          console.log(err);
        });
    },

  },
  created() {
    document.title = '唐元集公众号'
    this.id = this.$route.query.id;
    this.getdetail()
  }

}
</script>

<style scoped>
.containerbox {
  padding: 0.32rem;
  box-sizing: border-box;
  background: #fff;
}
.yingyangtitle {
  color: #02170b;
  font-size: 0.4rem;
}
.yingyangcontent {
  color: #666e69;
  font-size: 0.32rem;
}
.yingyangbox {
  margin-top: 0.6rem;
}
</style>