uniapp新闻项目

£神魔★判官ぃ 2023-08-17 16:28 222阅读 0赞

创建项目 uni-app
创建 hello uni-app 项目
把hello项目的common和components文件复制过来
page、index.vue
在这里插入图片描述

  1. <template>
  2. <view class="content">
  3. <view class="uni-list">
  4. <view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in news" :key="index"
  5. @tap="openinfo" :data-newsid="item.post_id">
  6. <view class="uni-media-list">
  7. <image class="uni-media-list-logo" :src="item.author_avatar"></image>
  8. <view class="uni-media-list-body">
  9. <view class="uni-media-list-text-top">{
  10. {item.title}}</view>
  11. <view class="uni-media-list-text-bottom uni-ellipsis">{
  12. {item.content}}</view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. news:[]
  24. }
  25. },
  26. onLoad:function() { //生命周期只执行一次
  27. uni.showLoading({
  28. title: '加载中...', //数据加载转转圈圈操作
  29. });
  30. uni.request({ //数据请求
  31. url: 'https://unidemo.dcloud.net.cn/api/news',
  32. method: 'GET',
  33. data: {},
  34. success: res => {
  35. console.log(res);
  36. this.news=res.data;
  37. uni.hideLoading(); // 关闭转圈圈操作
  38. },
  39. fail: () => {},
  40. complete: () => {}
  41. });
  42. },
  43. methods: { //方法
  44. openinfo(e){
  45. var newsid = e.currentTarget.dataset.newsid; //数据id
  46. console.log(newsid)
  47. uni.navigateTo({ //跳转页面
  48. url: '../info/info?newsid='+newsid, //url加id
  49. });
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. .uni-media-list-body{
  56. height: auto;
  57. }
  58. .uni-media-list-text-top{
  59. line-height: 1.6em;
  60. }
  61. </style>

page、info.vue

  1. <template>
  2. <view class="content">
  3. <view class="title">{
  4. {title}}</view>
  5. <view class="art-content">
  6. <rich-text class="richText" :nodes="strings"></rich-text>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. title:'',
  15. strings:''
  16. }
  17. },
  18. onLoad:function(e){
  19. uni.request({
  20. url: 'https://unidemo.dcloud.net.cn/api/news/36kr/'+e.newsid, //详情页数据请求
  21. method: 'GET',
  22. data: {},
  23. success: res => {
  24. console.log(res);
  25. this.title = res.data.title;
  26. this.strings = res.data.content; //组件渲染
  27. },
  28. fail: () => {},
  29. complete: () => {}
  30. });
  31. },
  32. methods: {
  33. }
  34. }
  35. </script>
  36. <style>
  37. .content{
  38. padding: 10upx 2%;
  39. width:96%;
  40. flex-wrap: wrap;
  41. }
  42. .title{
  43. line-height: 2em;
  44. font-weight: 700;
  45. font-size: 38upx;
  46. }
  47. .art-content{
  48. line-height: 2em;
  49. }
  50. </style>

在app.vue文件引入uni.css文件
@import url(“./common/uni.css”);
在这里插入图片描述
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,222人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Android实现新闻项目

    这是一个新闻类的项目,由于工作原因只能是一点一点写,后续会补充完整,有疑惑可以私信我.   首先是首页面,欢迎页实现     旋转 缩放 渐变 的效果 ,三个引导页实现侧滑