{5}首页开发-1-2

四、添加接口

  
  
  
  

五、关注功能

1、关注组件上添加判断v-if="!item.isFollow"

  
  
  
  
  1. +关注

2、通过this.$emit()向父组件传递信息

  
  
  
  
  1. follow(){

  2. console.log("关注");

  3. this.$emit('follow',this.index)

  4. },

3、父组件接收信息

  
  
  
  

  1. follow(e){

  2. console.log("已关注"+e)

  3. this.dynlist[e].isFollow = true;

  4. uni.showToast({

  5. title:"关注成功"

  6. })

  7. }

六、顶踩功能

1、顶踩组件上添加样式判断 :class="item.support.type==='unsupport'?'color-main':''

  
  
  
  
  1. hover-class="bounceIn" @click="doSupport('support')"

  2. :class="item.support.type==='support'?'color-main':''">

  3. {{item.support.support_count}}

  4. hover-class="bounceIn" @click="doSupport('unsupport')"

  5. :class="item.support.type==='unsupport'?'color-main':''">

  6. {{item.support.unsupport_count}}

2、通过this.$emit()向父组件传递信息

  
  
  
  
  1. doSupport(type){

  2. console.log(type);

  3. this.$emit('doSupport',

  4. {

  5. type:type,

  6. index:this.index

  7. })


  8. }

3、父组件接收信息

  
  
  
  
  1. doSupport(e){

  2. console.log(e)

  3. let item = this.dynlist[e.index];

  4. switch(item.support.type){

  5. case '':

  6. item.support[e.type+'_count']++

  7. break;

  8. case 'support':

  9. {

  10. if(e.type==='unsupport'){

  11. item.support['support_count']--

  12. item.support['unsupport_count']++

  13. }

  14. }

  15. break;

  16. default:

  17. if(e.type==='support'){

  18. item.support['support_count']++

  19. item.support['unsupport_count']--

  20. }

  21. break;

  22. }

  23. item.support.type = e.type;

  24. }


你可能感兴趣的:({5}首页开发-1-2)