vue2.0 + vux (五)api接口封装 及 首页 轮播图制作
1.安装 jquery 和 whatwg-fetch (优雅的异步请求API)
npm install jquery --save
npm install whatwg-fetch --save
2.api接口封装
api/index.js
/**
* 引入 异步请求API
*/
import "whatwg-fetch" const host_addr='http://192.168.1.110:8081/' /**
* 获取资讯列表
*/
export let getList = async (page, tag) => {
let response = await fetch(host_addr + `news_list?pageIndex=${page}&pageSize=20&catalog=${tag}`, {
method: 'GET',
mode: 'cors'
}).catch((error) => {
console.log(error)
})
return await response.json().catch((error) => {
console.log(error)
})
} /**
* 获取资讯详情
*/
export let getNewsDetail = async (id) => {
let response = await fetch(host_addr + `news_detail?id=${id}`, {
method: 'GET',
mode: 'cors'
}).catch((error) => {
console.log(error)
})
return await response.json().catch((error) => {
console.log(error)
})
} /**
* 获取博客列表
*/
export let getBlogList = async (page, tag) => {
let response = await fetch(host_addr + `blog_list?pageIndex=${page}&pageSize=20&catalog=${tag}`, {
method: 'GET',
mode: 'cors'
}).catch((error) => {
console.log(error)
})
return await response.json().catch((error) => {
console.log(error)
})
} /**
* 获取问答列表
*/
export let getQuestionList = async (page, tag) => {
let response = await fetch(host_addr + `question_list?pageIndex=${page}&pageSize=20&catalog=${tag}`, {
method: 'GET',
mode: 'cors'
}).catch((error) => {
console.log(error)
})
return await response.json().catch((error) => {
console.log(error)
})
} /**
* 获取活动列表
*/
export let getEventList = async (page, tag) => {
let response = await fetch(host_addr + `event_list?pageIndex=${page}&pageSize=20&catalog=${tag}`, {
method: 'GET',
mode: 'cors'
}).catch((error) => {
console.log(error)
})
return await response.json().catch((error) => {
console.log(error)
})
}
3.轮播图
<!-- 资讯 -->
<template>
<div>
<!-- 轮播图 -->
<swiper :list="imgs" auto style="width:100%;height:120px;margin:0 auto;" dots-class="custom-bottom" dots-position="center"></swiper>
</div>
</template> <script>
// 引入 vux 内部组件
import { Swiper } from 'vux'
// 引入 api接口文档
import { getList } from '../../api' // 轮播图列表
const imgList = [
'http://file06.16sucai.com/2016/0222/17714c3b51079911760e5ef7fdb553f6.jpg',
'http://pic.58pic.com/58pic/15/67/98/93C58PICjeM_1024.jpg',
'http://file06.16sucai.com/2016/0315/1df566087c24a94cd9534bc9bc1871ff.jpg'
]; // 轮播图图片地址列表
const urlList = imgList.map((one, index) => ({
url: 'javascript:', //这里填写图片点击的链接
img: one
})); export default {
name: 'NewsList',
components:{
Swiper
},
data(){
return {
imgs:urlList,
}
}
}
</script>
4.效果图

vue2.0 + vux (五)api接口封装 及 首页 轮播图制作的更多相关文章
- iOS回顾笔记(05) -- 手把手教你封装一个广告轮播图框架
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- js-BOM之offset家族、移动函数的封装升级(轮播图)
Obj.style.width/obj.style.height与obj.offsetWidth/obj.offsetHeight的区别: <style> #div1{ height: 2 ...
- 用require.js封装原生js轮播图
index.html页面: <!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...
- 在Nuxt中使用react-id-swiper封装公共的轮播图组件(移动端
首先就是引入swiper import Swiper from 'react-id-swiper': 一个轮播图首先要考虑到一种情况就是当只有一张图的时候是不是需要按轮播图来处理 一般情况下,一张图是 ...
- JS —— 轮播图中的缓动函数的封装
轮播图的根本其实就是缓动函数的封装,如果说轮播图是一辆跑动的汽车,那么缓动函数就是它的发动机,今天本文章就带大家由简入繁,封装属于自己的缓动函数~~ 我们从需求的角度开始,首先给出一个简单需求: 1. ...
- vue2.0 + vux (六)NewsList 资讯页 及 NewsDetail 资讯详情页
设置代理,避免出现跨域问题 /*设置代理,避免出现跨域问题*/ proxyTable: { '/api':{ target: 'https://www.oschina.net/action/apiv2 ...
- 微信小程序API接口封装
@ 目录 一,让我们看一下项目目录 二,让我们熟悉一下这三个文件目的(文件名你看着办) 三,页面js中如何使用 今天的API的封装,我们拿WX小程序开发中,对它的API (wx.request)对这个 ...
- 05-06 Flutter JSON和序列化反序列化、创建模型类转换Json数据、轮播图数据渲染:Flutter创建商品数据模型 、请求Api接口渲染热门商品 推荐商品
Config.dart class Config{ static String domain='http://jd.itying.com/'; } FocusModel.dart class Focu ...
- 基于ionic框架封装一个图片轮播指令的几点
在这里我想在项目中封装一个图片轮播的指令 (本项目使用的是ionic框架) 1)定义指令 define(['app'],function(myapp){ myapp.directive('myslid ...
随机推荐
- 零基础学 HTML5+CSS3 全彩版 明日科技 编著
第1章 基础知识 1.1 HTML概述 1.1.1 什么是HTML 1.1.2 HTML的发展历程 1.2 HTML文件的基本结构 1.2.1 HTML的基本结构 1.2.2 HTML的基本标记 1. ...
- MySQL5.7从入门到精通 (视频教学版) 刘增杰 编著
第1章 初识MySQL MySQL是一个开放源代码的数据库管理系统(DBMS),它是由MySQL AB公司开发.发布和支持的.MySQL是一个跨平台(Windows.Linux.UNIX.MacOS) ...
- MySQL 8.* 账号密码管理
修改密码: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的新密码' 通过以下命令可以查看修改的账号 ...
- Python socket粘包问题(最终解决办法)
套接字: 就是将传输层以下的协议封装成子接口 对于应用程序来说只需调用套接字的接口,写出的程序自然是遵循tcp或udp协议的 实现第一个功能个:实现:通过客户端向服务端发送命令,调取windows下面 ...
- Nginx报 No input file specified. 的问题解决之路 转
https://m.aliyun.com/yunqi/articles/34240 今天接手公司的一个项目,照例将项目clone下来,配置本地host,nginx,然后访问. 怎么回事?迅速在php的 ...
- wampSever的mysql操作
单击wampserver图标,选择mysql console 输入密码 123qwe,root用户默认密码为空 mysql客户端管理工具使用wampserver自带的phpmyadmin
- [NOIP2009] $Hankson$ 的趣味题 (数论,gcd)
题目链接 Solution 此题,用到的结论都是比较浅显的,但是,我竟然没想到反过来枚举... 只有50分... 被自己蠢哭... 结论比较浅显: 1.对于两个正整数\(a\),\(b\),设 \(g ...
- iOS-ARC机制
内存管理是开发软件中重要的一个课题.如果内存管理不当,轻者内存泄露,重者程序崩溃. 下面重要讲述一下iOS的ARC(Automatic Reference Counting))机制. ARC的历史由来 ...
- 爬虫【自动登陆github和抽屉】
自动登陆github用户详情页 代码 #! /usr/bin/env python # -*- coding: utf- -*- # __author__ = "wuxiaoyu" ...
- CodeForces 333E. Summer Earnings
time limit per test 9 seconds memory limit per test 256 megabytes input standard input output standa ...