zoukankan      html  css  js  c++  java
  • uniapp小实例-新闻列表及详情

    首先新建详情info文件夹及info.vue文件,然后在index页写列表部分代码:

    <template>
        <view class="content">
        <navigator class="newslist" :url="'../info/info?threadid=' + item.threadid"
                v-for="item in newslist" :key="item.threadid">
            <image src="../../static/logo.png" mode="widthFix"></image>
            <view class="news-title">{{item.title}}</view>
        </navigator>
        </view>
    </template>
    
    <script>
    var that;
    export default {
      data() {
        return {
            newslist: []
        }
      },
      onLoad() {
        that = this;
        this.getNews();
        },
      methods: {
        getNews() {
          uni.request({
            url:'https://www.easy-mock.com/mock/5d3914e09388917915bccb2e/shopapp/uniapp/newslist',
            method: 'GET',
            header: {'content-type': 'application/x-www-form-urlencoded'}, 
            success(res) {
                console.log(res);
                that.newslist = res.data.data;
            }
          })
        }
      },
    }
    </script>
    
    <style>
    .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    }
    .newslist{display: flex;width: 94%;padding:10upx 3%;margin:12upx 0;}
    .newslist image{width: 200upx;margin-right: 12upx;flex-shrink: 0;}
    .news-title{width:100%;font-size: 28upx;}
    </style>

    然后info.vue页,接收列表页传过来的参数:

    onLoad(options) {
        console.log(options.threadid)
    },

    然后通过这个参数请求详情的接口就可以得到数据了。

    var that;
    export default {
      data() {
        return {
            title: ''
        }
      },
      onLoad(options) {
        that = this;
        console.log(options.threadid)
        uni.request({
          url: '../home/getnoticeinfo',
          data: {
            threadid:options.threadid
          },
          success(res) {
            console.log(res);
            that.title = res.data.data.title;
          }
        })
      }
    }
  • 相关阅读:
    UVALive2678子序列
    UVA11549计算机谜题
    UVA11520填充正方形
    LA3635派
    UVALive3971组装电脑
    记录未完成题目
    SPOJ 6219 Edit distance字符串间编辑距离
    ACM组队安排-——杭电校赛(递推)
    逆袭指数-——杭电校赛(dfs)
    油菜花王国——杭电校赛(并查集)
  • 原文地址:https://www.cnblogs.com/joe235/p/12574250.html
Copyright © 2011-2022 走看看