All Projects → superman66 → Vue2.x Douban

superman66 / Vue2.x Douban

Vue2.0实现简易豆瓣电影webApp

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue2.x Douban

Netease yanxuan
vue版网易严选,体验网易严选购物流程,线上访问:http://zhaoboy.bid/yanxuan/#/
Stars: ✭ 417 (-45.77%)
Mutual labels:  vue-cli
Vuetify Admin Dashboard
A Crud Admin panel made from Vue js and Vuetify
Stars: ✭ 481 (-37.45%)
Mutual labels:  vue-cli
Vue Chat
📲 A web chat application. Vue + node(koa2) + Mysql + socket.io
Stars: ✭ 617 (-19.77%)
Mutual labels:  vue-cli
One
基于Spring Boot和Vue2开发的前后端分离的后台管理系统
Stars: ✭ 426 (-44.6%)
Mutual labels:  vue-cli
Vue2 Calendar
vue 2.x calendar component
Stars: ✭ 477 (-37.97%)
Mutual labels:  vue-cli
Dashboard
A dashboard scaffolding based on Vue.js 3.0 created by Vite.
Stars: ✭ 497 (-35.37%)
Mutual labels:  vue-cli
Savuegram
A simple social media web app built with Vue.js and Firebase's Cloud Firestore as a way to teach people how to build a real-world app using the two technologies. Follow along with our tutorial.
Stars: ✭ 412 (-46.42%)
Mutual labels:  vue-cli
Vue Ts Daily
基于vue、Typescript、pwa的一款习惯养成app
Stars: ✭ 735 (-4.42%)
Mutual labels:  vue-cli
Vue Develop Template
A Vue.js template that can support more than 100 thousand lines of code in our business, I hope it can help you too~
Stars: ✭ 481 (-37.45%)
Mutual labels:  vue-cli
Ruoyi Vue
(RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离权限管理系统
Stars: ✭ 596 (-22.5%)
Mutual labels:  vue-cli
Cookiecutter Django Vue
Cookiecutter Django Vue is a template for Django-Vue projects.
Stars: ✭ 462 (-39.92%)
Mutual labels:  vue-cli
Douban
Douban book website demo by server side render
Stars: ✭ 468 (-39.14%)
Mutual labels:  vue-cli
Lucky wheel
vue 实现的抽奖大转盘,奖项个数可配置
Stars: ✭ 535 (-30.43%)
Mutual labels:  vue-cli
Vue2 blog
使用vue2.x + vue-cli +vue-router+ vuex + axios + mysql + express + pm2 + webpack+nginx构建的具有登录,注册,留言,用户发帖,用户评论等功能的SPA Blog。注意,注意,注意,后端API全部自己手写,很适合刚学习vue以及express的小伙伴学习,喜欢请Star鼓励一下我,谢谢!项目预览:
Stars: ✭ 417 (-45.77%)
Mutual labels:  vue-cli
Vue Admin Webapp
this is a admin project
Stars: ✭ 673 (-12.48%)
Mutual labels:  vue-cli
Vue Cms
基于 Vue 和 ElementUI 构建的一个企业级后台管理系统
Stars: ✭ 415 (-46.03%)
Mutual labels:  vue-cli
Iview
admin template based on Vue CLI 3 & iView. 基于 Vue CLI 3 + iView 的 Vue.js 后台管理系统。
Stars: ✭ 485 (-36.93%)
Mutual labels:  vue-cli
React Article Bucket
总结,积累,分享,传播JavaScript各模块核心知识点文章全集,欢迎star,issue(勿fork,内容可能随时修改)。webpack核心内容部分请查看专栏: https://github.com/liangklfangl/webpack-core-usage
Stars: ✭ 750 (-2.47%)
Mutual labels:  vue-cli
Iview Cli
Create an iView project in visual way
Stars: ✭ 729 (-5.2%)
Mutual labels:  vue-cli
Vue Seed
a boilerplate for large vue project with ElementUI 2.x
Stars: ✭ 555 (-27.83%)
Mutual labels:  vue-cli

Change Log

  • 2017-3-15:新增 node 服务转发 api 请求
  • 2017-3-17:增加在线访问地址,node 服务转发 api 请求部署到 heroku

运行项目

clone项目到本地,进入项目文件夹,安装依赖

git clone https://github.com/superman66/vue2.x-douban.git
cd vue2.x-douban
npm install

然后运行项目

npm run dev

接着运行 node,启动服务, 注意:这一步的 node 转发服务一定要启动,要不然无法正常访问豆瓣 API

cd node-proxy
node index.js

//启动成功后,将看到输出
// HTTP Server is running in http://127.0.0.1:8081

最后打开浏览器,输入localhost:8880即可访问。效果图如下:

text

如果遇到本地运行时,豆瓣的图片部分不可见,请参见该 issue:为什么图片加载会有问题?

戳我查看 demo

注意:由于heroku在国外,而且我用的是免费版,当长时间没有连接的话,node服务会被休眠。如果处于休眠状态下,用户访问速度会比较慢,还有可能出现接口请求出现错误。遇到这种情况,刷新重试即可。

路由

应用包括下面4个路由

  • /movies 首页,包含正在上映榜单和即将上映榜单的电影信息,首页只显示各个榜单的前8条数据;
  • /movie-list 榜单列表页面,显示榜单列表信息;
  • /movie/subject/:id 电影详情页面;
  • /movie/search 电影搜索列表页面。

项目结构

.
├── README.md
├── build // vue-cli 自带的配置文件
│   ├── build.js
│   ├── check-versions.js
│   ├── dev-client.js
│   ├── dev-server.js
│   ├── utils.js
│   ├── webpack.base.conf.js
│   ├── webpack.dev.conf.js
│   └── webpack.prod.conf.js
├── config  // vue-cli 自带的配置文件
│   ├── dev.env.js
│   ├── index.js
│   └── prod.env.js
├── git.sh
├── index.html
├── node-proxy  // node 转发API请求,解决跨域问题
│   └── index.js
├── package.json
├── src
│   ├── App.vue
│   ├── assets
│   │   ├── list.scss
│   │   ├── logo.png
│   │   ├── search-btn.png
│   │   └── style.scss
│   ├── components
│   │   ├── Hello.vue
│   │   ├── Spinner.vue
│   │   └── header.vue
│   ├── main.js // 入口文件
│   ├── router.js // 路由
│   ├── store
│   │   ├── api.js  // 抽取访问api的方法
│   │   ├── modules
│   │   │   └── movie.js
│   │   ├── store.js
│   │   └── types.js
│   └── views
│       ├── index.vue
│       ├── movie
│       │   ├── movie-detail.vue
│       │   ├── movie-list.vue
│       │   ├── movies.vue
│       │   └── search-list.vue
│       └── vuex-demo.vue
├── static
└── tree.md

第三方库

豆瓣API

该应用使用了下面4个api:

  • /v2/movie/search?q={text} 电影搜索api;
  • /v2/movie/in_theaters 正在上映的电影;
  • /v2/movie/coming_soon 即将上映的电影;
  • /v2/movie/subject/:id 单个电影条目信息。

更多关于豆瓣的api可以前往豆瓣api官网查看。

需要注意的是,由于豆瓣api的跨域问题,并不能直接通过ajax请求访问。不过vue-cli提供了代理的配置。 我们需要在/config/index.js中配置代理:

dev: {
  env: require('./dev.env'),
  port: 8880,
  assetsSubDirectory: 'static',
  assetsPublicPath: '/',
  proxyTable: {
    '/api': {
      target: 'http://api.douban.com/v2',
      changeOrigin: true,
      pathRewrite: {
        '^/api': ''
      }
    }
  },
  cssSourceMap: false
}

proxyTable这个属性中,配置target属性为我们要代理的目标地址。这里我们写成http://api.douban.com/v2,这样我们就可以在应用中调用/api/movie/in_theaters来访问http://api.douban.com/v2/movie/in_theaters,从而解决跨域的问题。

关于vue-cli更多关于跨域的设置可以看官网文档

Node.js 转发API请求

由于有同学在问,项目执行npm run build打包之后,豆瓣 API 代理配置不起作用,无法访问豆瓣API的问题。 所以新增了Node.js http服务,用于转发API请求,解决跨域问题。 安装依赖

Node.js转发用到了 expresssuperagent. superanget是一个 Node.js HTTP client。

npm i express superagent -S

定义接口 根据前端所需,定义了如下三个接口:

app.get('/movie/:type', function (req, res) {
  var sreq = request.get(HOST + req.originalUrl)
  sreq.pipe(res);
  sreq.on('end', function (error, res) {
    console.log('end');
  });
})

app.get('/movie/subject/:id', function (req, res) {
  var sreq = request.get(HOST + req.originalUrl)
  sreq.pipe(res);
  sreq.on('end', function (error, res) {
    console.log('end');
  });
})

app.get('/movie/search', function (req, res) {
  var sreq = request.get(HOST + req.originalUrl)
  sreq.pipe(res);
  sreq.on('end', function (error, res) {
    console.log('end');
  });
})

CORS设置

跨源资源共享 ( CORS )机制让Web应用服务器能支持跨站访问控制,从而使得安全地进行跨站数据传输成为可能。

主要是通过设置Access-Control-Allow-Origin: *

app.all('*', function (req, res, next) {
  if (!req.get('Origin')) return next();
  // use "*" here to accept any origin
  res.set('Access-Control-Allow-Origin', '*');
  res.set('Access-Control-Allow-Methods', 'GET');
  res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
  // res.set('Access-Control-Allow-Max-Age', 3600);
  if ('OPTIONS' == req.method) return res.send(200);
  next();
});

端口监听

app.listen(8081, function () {
  console.log('HTTP Server is running in http://127.0.0.1:8081')
})

启动

cd node-proxy
node index.js

具体见node-proxy/index.js

更多关于 Node.js 转发 api 请求,请戳完整项目:node-proxy-api

关于vuex

如果你想了解vuex的用法,可以切换到vuex分支,在该分支下,所有的state都采用vuex来管理。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].