知乎
  • 当前位置:   article > 正文

    【Mena】Vue实现新闻小组件_el-tabs 制作新闻列表

    el-tabs 制作新闻列表
    <template>
      <div id="HotNews" class="newsMain">
        <el-tabs v-model="activeName"  @tab-click="handleClick">
    
        <el-tab-pane   name="first">
          <span class="newsTitle" slot="label" >知乎</span>
    
          <li v-for="zhihuNew in zhihuNews.info.slice(0,4)" :key="zhihuNew.rank" ><a class="newsLink" target="_blank" :href="zhihuNew.url">{{+zhihuNew.rank+'\u00a0'+'\u00a0'+zhihuNew.keyword}}</a></li>
          
        </el-tab-pane>
    
        <el-tab-pane  name="second">
          <span class="newsTit'le" slot="label" >百度</span>
          <li v-for="baiduNew in baiduNews.info.slice(0,4)" :key="baiduNew.rank"><a class="newsLink" target="_blank" :href="baiduNew.url">{{baiduNew.rank+'\u00a0'+'\u00a0'+baiduNew.keyword+'\u00a0'+'\u00a0'+'\u00a0'+'\u00a0'+baiduNew.hotValue}}</a></li>  
        </el-tab-pane>
        <el-tab-pane  name="third">
          <span class="newsTit'le" slot="label" >微博</span>
          <li v-for="weiboNew in weiboNews.info.slice(0,4)" :key="weiboNew.rank"><a class="newsLink" target="_blank" :href="weiboNew.url">{{weiboNew.rank+'\u00a0'+'\u00a0'+weiboNew.keyword }}</a></li>
         
          
        </el-tab-pane>
        </el-tabs>
       
      </div>
    </template>
     
    <script>
    import axios from 'axios';
    import { keys } from 'shelljs/commands';
    import { re } from 'semver';
    import Qs from 'qs'
    export default {
        name: 'HotNews',
        data(){
            return{
              
                zhihuNews: {
                  name: '知乎',
                  info: []
                },
    
                weiboNews:{
                  name: '微博',
                  info: []
                },
    
                baiduNews: {
                  name: '百度',
                  info: []
                },
    
                activeName : 'first'
            }
        },
    
          created() {             
            let accessKey = 'd9c3845930ea8a5e5208b591b9085faf'
            let secretKey = '735762a6537ddff2fa3c355ee40d4050'
            
            axios({
              method: 'GET',
              url: '/api/api/resou/v1/zhihu',
              headers: { 			  //要在请求头里添加身份凭证
                'access-key': accessKey,
                'secret-key': secretKey
              },
            }) 
            .then(res =>{
              
              this.zhihuNews.info = res.data.data;
    
              
                
            })
            .catch(res => {
                
            });
    
            axios({
              method: 'GET',
              url: '/api/api/resou/v1/baidu',
              headers: {
                'access-key': accessKey,
                'secret-key': secretKey
              },
            }) 
            .then(res => {
                this.baiduNews.info = res.data.data
                
                
            })
            .catch(res => {
                
            });
    
            axios({
              method: 'GET',
              url: '/api/api/resou/v1/weibo',
              headers: {
                'access-key': accessKey,
                'secret-key': secretKey
              },
            }) 
            .then(res => {
                this.weiboNews.info = res.data.data
                
                
            })
            .catch(res => {
                
            });
    
           
          },
        
        methods: {
          
            handleClick(tab, event) {
          }
          },
      }
    
    </script>
    
    <style scoped>
    
    
      .newsContent{
        width:100%;
        height: 100%;
      }
    
      .newsTitle{
        color: white;
        
      }
    
      #HotNews{
        color: #fff;
        border-radius: 16px;
        background-image: linear-gradient(135deg,rgba(20,20,20,.7),rgba(20,20,20,.4));
        text-align: left;
      }
      #HotNews li{
        font-size: 12px;
        list-style: none;
        height: 100%;
        line-height: 23px;
        margin-left: 3px;
        
    
      }
    
      .newsMain /deep/ .el-tabs__header{  //这里使用了深度作用选择器
        height: 40px;
        margin-bottom: 5px;
      }
    
      .newsMain /deep/ .el-tabs__item{    
           color:white !important;
           font-size: 13px;
           width: 55px;
           
           text-align: center  !important;
       }
    
       
    
       .newsMain /deep/  .el-tabs__nav{
         width: 250px;
       }
    
      
      .newsLink{
        text-decoration:none;
      }
    
      a:link{
        color: white
        
        
      }
      
      a:visited{
        color: white;
      }
    
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
    推荐阅读