设置代理,避免出现跨域问题

  1. /*设置代理,避免出现跨域问题*/
  2. proxyTable: {
  3. '/api':{
  4. target: 'https://www.oschina.net/action/apiv2/',
  5. changeOrigin: true,
  6. pathRewrite: {
  7. '^/api': ''
  8. }
  9. }
  10. },

api/index.js  接口配置

  1. /**
  2. * 引入 异步请求API
  3. */
  4. import "whatwg-fetch"
  5.  
  6. const host_addr='http://192.168.1.110:8081/'
  7.  
  8. /**
  9. * 获取资讯列表
  10. * 解决跨域问题: 用 '/api' 代替 host_addr
  11. */
  12. export let getList = async (page, tag) => {
  13. let response = await fetch('/api' + `news_list?pageIndex=${page}&pageSize=20&catalog=${tag}`, {
  14. method: 'GET',
  15. mode: 'cors'
  16. }).catch((error) => {
  17. console.log(error)
  18. })
  19. return await response.json().catch((error) => {
  20. console.log(error)
  21. })
  22. }
  23.  
  24. /**
  25. * 获取资讯详情
  26. */
  27. export let getNewsDetail = async (id) => {
  28. let response = await fetch('/api' + `news_detail?id=${id}`, {
  29. method: 'GET',
  30. mode: 'cors'
  31. }).catch((error) => {
  32. console.log(error)
  33. })
  34. return await response.json().catch((error) => {
  35. console.log(error)
  36. })
  37. }
  38.  
  39. /**
  40. * 获取博客列表
  41. */
  42. export let getBlogList = async (page, tag) => {
  43. let response = await fetch(host_addr + `blog_list?pageIndex=${page}&pageSize=20&catalog=${tag}`, {
  44. method: 'GET',
  45. mode: 'cors'
  46. }).catch((error) => {
  47. console.log(error)
  48. })
  49. return await response.json().catch((error) => {
  50. console.log(error)
  51. })
  52. }
  53.  
  54. /**
  55. * 获取问答列表
  56. */
  57. export let getQuestionList = async (page, tag) => {
  58. let response = await fetch(host_addr + `question_list?pageIndex=${page}&pageSize=20&catalog=${tag}`, {
  59. method: 'GET',
  60. mode: 'cors'
  61. }).catch((error) => {
  62. console.log(error)
  63. })
  64. return await response.json().catch((error) => {
  65. console.log(error)
  66. })
  67. }
  68.  
  69. /**
  70. * 获取活动列表
  71. */
  72. export let getEventList = async (page, tag) => {
  73. let response = await fetch(host_addr + `event_list?pageIndex=${page}&pageSize=20&catalog=${tag}`, {
  74. method: 'GET',
  75. mode: 'cors'
  76. }).catch((error) => {
  77. console.log(error)
  78. })
  79. return await response.json().catch((error) => {
  80. console.log(error)
  81. })
  82. }

1.资讯页

NewsList.vue

  1. <!-- 资讯 -->
  2. <template>
  3. <div>
  4. <!-- 轮播图 -->
  5. <swiper :list="imgs" auto style="width:100%;height:120px;margin:0 auto;" dots-class="custom-bottom" dots-position="center"></swiper>
  6. <!-- 滚动列表 -->
  7. <div>
  8. <scroller lock-x scrollbar-y :height="height" :bounce=false :scrollbarY="false" ref="scroller">
  9. <div class="news-wrap-list">
  10. <cell v-for="x in Objlist" :title="x.title" :link="{path:'/newsDetail',query:{id:x.id,tag:'资讯'}}" :inline-desc="x.body" :key="x.id">
  11. <img class="ic_img" slot="icon" src="../../assets/img/ic_label_today.png">
  12. <div>
  13. <span class="pubdate">{{x.pub_date}}</span>
  14. </div>
  15. </cell>
  16. </div>
  17. </scroller>
  18. </div>
  19. </div>
  20. </template>
  21.  
  22. <script>
  23. // 引入 vux 内部组件
  24. import { Swiper, Scroller, Cell } from 'vux'
  25. // 引入 api接口文档
  26. import { getList } from '../../api/index.js'
  27.  
  28. // 轮播图列表
  29. const imgList = [
  30. 'http://file06.16sucai.com/2016/0222/17714c3b51079911760e5ef7fdb553f6.jpg',
  31. 'http://pic.58pic.com/58pic/15/67/98/93C58PICjeM_1024.jpg',
  32. 'http://file06.16sucai.com/2016/0315/1df566087c24a94cd9534bc9bc1871ff.jpg'
  33. ];
  34.  
  35. // 轮播图图片地址列表
  36. const urlList = imgList.map((one, index) => ({
  37. url: 'javascript:', //这里填写图片点击的链接
  38. img: one
  39. }));
  40.  
  41. export default {
  42. name: 'NewsList',
  43. components:{
  44. Swiper,
  45. Scroller,
  46. Cell
  47. },
  48. data(){
  49. return {
  50. imgs:urlList,
  51. Objlist:[],
  52. ishow:false,
  53. pageIndex:1,
  54. catalog:0,
  55. height: ''
  56. }
  57. },
  58. created(){
  59. // 获取屏幕高度
  60. this.height = document.documentElement.clientHeight - 46 - 44 - 120 - 53 + 'px';
  61. console.log(this.height);
  62. // 请求列表数据
  63. this.getList();
  64. },
  65. methods:{
  66. // 异步请求
  67. async getList(){
  68. // 获取列表数据
  69. let data = await getList(this.pageIndex, this.catalog);
  70. console.log(data);
  71. // 获取资讯列表数据
  72. var news_list = data.obj_list;
  73. // 判断是否还有数据
  74. if(news_list.length > 0){
  75. this.ishow = true;
  76. for(var i=0;i<news_list.length;i++){
  77. var time = news_list[i].pub_date;
  78. // 修改日期显示格式
  79. var bngDate = new Date(time.replace(/-/g,"/"));
  80. var endDate = new Date();
  81. var minutes = (endDate.getTime() - bngDate.getTime())/60/1000;
  82.  
  83. // 时间段 判断pub_date显示内容
  84. if(minutes >= 60){
  85. minutes = minutes/60;
  86. var dateTime = parseInt(minutes);
  87. if(dateTime >= 48){
  88. news_list[i].pub_date = "2天前";
  89. }else if(dateTime >= 24){
  90. news_list[i].pub_date = "昨天";
  91. }else{
  92. news_list[i].pub_date = dateTime + "小时以前";
  93. }
  94. }else{
  95. var minute = parseInt(minutes);
  96. news_list[i].pub_date = minute + "分钟以前";
  97. }
  98.  
  99. news_list[i].title = " " + news_list[i].title;
  100. this.Objlist.push(news_list[i]);
  101. }
  102. }
  103. this.locked = false;
  104. this.loading = false;
  105. },
  106. load(uuid){
  107. setTimeout(() => {
  108. this.$broadcast('pulldown:reset', uuid);
  109. }, 1000);
  110. }
  111. }
  112. }
  113. </script>
  114.  
  115. <style lang="less" scoped>
  116. .ic_img{
  117. position:absolute; top:10px; left: 5px;
  118. width:15px;
  119. height:15px;
  120. }
  121. .weui_cell_bd>p{
  122. font-size:15px;
  123. }
  124. .vux-label-desc{
  125. padding-right:15px;
  126. }
  127. .weui_cell_bd.weui_cell_primary{
  128. padding-left:5px;
  129. }
  130. .news-wrap-list {
  131. height: 2800px;
  132. overflow: hidden;
  133. }
  134. .pubdate{
  135. font-size:5px;
  136. }
  137. </style>

2.资讯详情页

NewsDetail.vue

  1. <!-- 资讯详情页 -->
  2. <template>
  3. <div>
  4. <tabbar class="tabbar">
  5. <div class="title">{{title}}</div>
  6. <tabbar-item class="search"></tabbar-item>
  7. </tabbar>
  8. <h3 class="htitle">{{result.title}}</h3>
  9. <scroller lock-x scrollbar-y :height="height" :bounce=false :scrollbarY="false" ref="scroller">
  10. <div id="content" class="contentDiv"></div>
  11. </scroller>
  12. </div>
  13. </template>
  14.  
  15. <script>
  16. import { Tabbar,TabbarItem,Scroller} from 'vux'
  17. import { getNewsDetail } from '../../api/index.js'
  18. // 引入 jquery
  19. import "jquery"
  20. var $ = require('jquery');
  21. window.$ = $;
  22.  
  23. export default{
  24. name:'NewsDetail',
  25. data () {
  26. return {
  27. title: '',
  28. result:'',
  29. body: '',
  30. height: ''
  31. }
  32. },
  33. components:{
  34. Tabbar,
  35. TabbarItem,
  36. Scroller
  37. },
  38. created () {
  39. // 获取屏幕高度
  40. this.height = document.documentElement.clientHeight - 50 - 100 - 53 + 'px';
  41. console.log(this.$route.query);
  42. this.title = this.$route.query.tag;
  43. this.getDetail();
  44. },
  45. methods:{
  46. // 获取消息id,根据id到服务端请求详情
  47. async getDetail() {
  48. let data = await getNewsDetail(this.$route.query.id);
  49. console.log(data);
  50. if(data.code >= 0){
  51. this.result = data.obj_data;
  52. this.body = data.obj_data.body;
  53. $(".contentDiv").html(this.body);
  54. //获取div高度,根据该高度设定滑动区域,避免footer位置变化
  55. var contentHeight=$(".contentDiv").height() + 50;
  56. document.getElementById("content").style.height = contentHeight + "px";
  57. this.$nextTick(() => {
  58. this.$refs.scroller.reset();
  59. });
  60. }
  61. }
  62. }
  63. }
  64. </script>
  65.  
  66. <style lang="less" scoped>
  67. .tabbar{
  68. background-color:#00CC66;
  69. height:50px;
  70. position:relative;
  71. }
  72. .search{
  73. position:absolute;right:5px;top:5px;z-index:999;
  74. }
  75. .title{
  76. text-align:center;
  77. margin:auto;
  78. color:white;
  79. line-height:50px;
  80. font-size:18px;
  81. }
  82. .htitle{
  83. text-align:center;
  84. margin:auto;
  85. color:black;
  86. line-height:50px;
  87. height: 100px;
  88. }
  89. </style>

3.效果图

vue2.0 + vux (六)NewsList 资讯页 及 NewsDetail 资讯详情页的更多相关文章

  1. vue2.0 + vux (四)Home页

    1.综合页(首页) Home.vue <!-- 首页 --> <template> <div> <!-- 顶部 标题栏 --> <app-head ...

  2. vue2.0 + vux (三)MySettings 页

    1.MySettings.vue <!-- 我的设置 --> <template> <div> <img class="img_1" sr ...

  3. vue2.0 + vux (五)api接口封装 及 首页 轮播图制作

    1.安装 jquery 和 whatwg-fetch (优雅的异步请求API) npm install jquery --save npm install whatwg-fetch --save 2. ...

  4. vue2.0 + vux (二)Footer组件

    1.Footer组件 Footer.vue <!-- 底部 footer --> <template> <div> <tabbar> <!-- 综 ...

  5. vue2.0 + vux (一)Header 组件

    1.main.js import Vue from 'vue' import FastClick from 'fastclick' import VueRouter from 'vue-router' ...

  6. vue2.0 + vux 项目搭建

    1.快速搭建项目模板 因为项目使用vux,所以推荐使用vux官网的airyland/vux2 模板,vue-cli工具是vue项目的搭建脚手架 默认为 webpack2 模板,如果你需要使用webpa ...

  7. 【数据售卖平台】—— Vue2.0入门学习项目爬坑

    前言:这个项目是我从零学习Vue2.0时用于练习基础知识的入门项目,包含了Vue2.0几乎所有项目都会用到的基础功能,是新手用来练手的好项目,这里温故知新对功能点做一个总结.github地址:http ...

  8. Vue2.0史上最全入坑教程(下)—— 实战案例

    书接上文 前言:经过前两节的学习,我们已经可以创建一个vue工程了.下面我们将一起来学习制作一个简单的实战案例. 说明:默认我们已经用vue-cli(vue脚手架或称前端自动化构建工具)创建好项目了 ...

  9. 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 二十四║ Vuex + JWT 实现授权验证登录

    壹周回顾 哈喽,又是元气满满的一个周一,又与大家见面了,周末就是团圆节了,正好咱们的前后端也要团圆了,为什么这么说呢,因为以后的开发可能就需要前后端一起了,两边也终于会师了,还有几天Vue系列就基本告 ...

随机推荐

  1. Leetcode 452.用最少数量的箭引爆气球

    用最少数量的箭引爆气球 在二维空间中有许多球形的气球.对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标.由于它是水平的,所以y坐标并不重要,因此只要知道开始和结束的x坐标就足够了.开始坐 ...

  2. django demo --blog

    详情,请看虫师博客http://www.cnblogs.com/fnng/p/3737964.html 和https://my.oschina.net/matrixchan/blog/184445  ...

  3. TOJ4483: Common Digit Pairs

    4483: Common Digit Pairs  Time Limit(Common/Java):3000MS/9000MS     Memory Limit:65536KByteTotal Sub ...

  4. Linux定时任务Crontab命令详解 转

      linux 系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服务是默认启动的.另 外, 由于使用者自己也可以设置计划任务,所 ...

  5. js方法encodeURI后,关于get请求url长度的限制测试与总结

    (本文仅作个人记录只用比较啰嗦,重点只看红字部分即可) Test.jsp 请求test1.jsp IE11环境下,get请求url最多4096个字节: 请求的是http://localhost:908 ...

  6. java并发框架Executor介绍

    Executor框架是指java 5中引入的一系列并发库中与executor相关的一些功能类,其中包括线程池,Executor,Executors,ExecutorService,Completion ...

  7. Opus 和 AAC 声音编码格式

    Opus编码器 是一个有损声音编码的格式,由互联网工程任务组(IETF)近来开发,适用于网络上的实时声音传输,标准格式为RFC 6716.Opus 格式是一个开放格式,使用上没有任何专利或限制. Op ...

  8. ROS学习网址【原创】

    ROS学习网址 http://www.ros.org/ http://www.ros.org/news/book/ http://wiki.ros.org/ http://blog.exbot.net ...

  9. CAR_TUNE_VALUE 校準

    CAR_TUNE_VALUE 是用來校準 流過電池上的電流 與 系統偵測到的電流 的一致性, 假電 若您是使用假電, 請拔除零件, 僅留下必要元件,如thermal電阻,ID 電阻, 減少量測 fue ...

  10. java打包python到exe文件

    最近想把写的python代码打包,以供没用安装python环境的同事使用,需求如下: 无python环境也可执行 文件尽量少,不要太乱 程序体积尽量小 如果需要更新的话重复类库不用更新 采用方案如下: ...