微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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: []
    }
  },
  onl oad() {
    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: ''
    }
  },
  onl oad(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;
      }
    })
  }
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐