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;
          }
        })
      }
    }
  • 相关阅读:
    事务管理
    QQ邮箱开启SMTP方法如何授权
    基于JavaMail的Java邮件发送:简单邮件发送
    Spring MVC 响应视图(六)
    Spring MVC 数据绑定 (四)
    Spring MVC Spring中的Model (五)
    Spring MVC 拦截器 (十)
    Spring MVC 异常处理 (九)
    Java 骚操作--生成二维码
    Java MD5校验与RSA加密
  • 原文地址:https://www.cnblogs.com/joe235/p/12574250.html
Copyright © 2011-2022 走看看