test.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <div class="hello">
  3. <div v-for='item in showList'>{{item}}</div>
  4. <div @click="showAll = !showAll" class="show-more">{{word}}</div>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. data () {
  10. return {
  11. toLearnList:[
  12. 'html','css','javascript','java','php' //进行显示的数据
  13. ],
  14. showAll:false,                 //标记数据是否需要完全显示的属性
  15. }
  16. },
  17. computed:{
  18. showList:function(){
  19. if(this.showAll == false){ //当数据不需要完全显示的时候
  20. var showList = [];                //定义一个空数组
  21. if(this.toLearnList.length > 3){       //这里我们先显示前三个
  22. for(var i=0;i<3;i++){
  23. showList.push(this.toLearnList[i])
  24. }
  25. }else{
  26. showList = this.toLearnList
  27. }
  28. return showList;                 //返回当前数组
  29. }else{
  30. return this.toLearnList;
  31. }
  32. },
  33. word:function(){
  34. if(this.showAll == false){           //对文字进行处理
  35. return '点击展开'
  36. }else{
  37. return '点击收起'
  38. }
  39. }
  40. },
  41. methods: {
  42. }
  43. }
  44. </script>
  45. <style>
  46. </style>