1、搭建项目框架

使用vue-cli 没安装的需要先安装

npm intall -g vue-cli

使用vue-cli生成项目框架

vue init webpack-simple vue-movie
然后一路回车

接着 进入项目目录

cd vue-movie

然后安装项目依赖包

cnpm install
没安装cnpm的先执行这个命令
npm install -g cnpm --registry=https://registry.npm.taobao.org
接着 npm run dev

看到这个界面 说明前面没啥问题了

2、安装需要的依赖包

该项目需要用到vue-router bootstrap

所以先安装这两个包
cnpm install vue-router bootstrap -D
然后在 index.html 页面引用下boostrap.css和另一个需要用到的css文件

 <link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="http://v3.bootcss.com/examples/dashboard/dashboard.css">

3、编写代码

App.vue

 来到src目录下的App.vue中添加下列代码
<template>
<div id="app">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false"
aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">基于Vue2.0的一个豆瓣电影App</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active" v-focus="{server:currentRoute}">
<router-link to="/in_theaters/0">正在热映</router-link>
</li>
<li v-focus="{server:currentRoute}">
<router-link to="/coming_soon/0">即将上映</router-link>
</li>
<li v-focus="{server:currentRoute}">
<router-link to="/top250/0">Top</router-link>
</li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<router-view></router-view>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import jsonp from './js/jsonp.js'
import config from './js/config.js'
export default {
name: 'app',
data() {
return {
currentRoute: '',
search: ''
}
},
created() {
this.request();
},
methods: {
request() {
var server = this.$route.params.server;
this.currentRoute = server;
},
data: {
jsondata: {}
},
Search() {
this.$router.push({ path: '/search/0?t=' + this.search, params: { t: this.search } });
}
},
watch: {
'$route': 'request'
}
}
</script>

然后在src目录下新建一个components文件夹

在该文件夹下创建一个movielist.vue
添加以下代码
<template>
<div>
<h1 class="page-header">{{jsondata.title}}</h1>
<ul class="list-group">
<li class="list-group-item" v-for="(item,index) in jsondata.subjects">
<span class="badge">{{item.rating.average}}</span>
<div class="media-left">
<router-link :to="{path:'/detail/'+item.id}">
<img class="media-object" :src="item.images.small" alt="">
</router-link>
</div>
<div class="media-body">
<h3 class="media-heading">{{item.title}}</h3>
<p>
<span>类型:</span><span>{{item.genres.join('、')}}</span>
</p>
<p>
<span>导演:</span> <span v-for="(val,index) in item.casts">{{val.name + (index==item.casts.length-1?'':'、')}}</span>
</p>
</div>
</li>
</ul>
<div id="layear" v-show="!show">
<p>当前第{{parseInt(currentPage) +1}}页、共 {{countPage}}页</p>
<nav>
<ul class="pager">
<li :class="{disabled:currentPage<=0}">
<router-link :to="{path:'/'+server+'/'+ (currentPage<=0?0:(parseInt(currentPage)-1))}">上一页</router-link>
</li>
<li :class="{disabled:currentPage>=countPage}">
<router-link :to="{path:'/'+server+'/'+(parseInt(currentPage) + parseInt(1))}">下一页</router-link>
</li>
</ul>
</nav>
</div>
<div class="spinner" v-show="show">
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div> </div>
</template>
<script>
import Vue from 'vue'
import jsonp from '../js/jsonp.js'
import config from '../js/config.js'
export default {
created() {
this.request();
},
data() {
return {
currentPage: 0,
jsondata: {},
countPage: 0,
server: '',
show: 'true'
}
},
methods: {
request() {
this.show = true;
var server = this.$route.params.server;
this.server = server;
this.currentPage = this.$route.params.page;
var count = 10;
jsonp(config.apiServer + server, { count: count, start: this.currentPage * count, q: this.$route.query.t }, function (data) {
this.jsondata = data;
this.countPage = Math.ceil(this.jsondata.total / this.jsondata.count);
this.show = false;
}.bind(this))
}
},
watch: {
'$route.path': 'request',
'$route.params':'request'
}
} </script>
<style scoped>
.spinner {
width: 60px;
height: 60px;
margin: 100px auto;
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
} .double-bounce1,
.double-bounce2 {
width: 100%;
height: 100%;
border-radius: 50%;
background-color: #67CF22;
opacity: 0.6;
position: absolute;
top: 0;
left: 0; -webkit-animation: bounce 2.0s infinite ease-in-out;
animation: bounce 2.0s infinite ease-in-out;
} .double-bounce2 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
} @-webkit-keyframes bounce {
0%,
100% {
-webkit-transform: scale(0.0)
}
50% {
-webkit-transform: scale(1.0)
}
} @keyframes bounce {
0%,
100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
}
50% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}
</style>

接着在src目录下创建js文件夹 存放js文件

新建一个jsonp.js
var jsonp = function (url, data, callback) {
var cbFuncName = 'jsonp_fun' + Math.random().toString().replace('.', '');
window[cbFuncName] = callback;
var queryString = url.indexOf('?') == -1 ? '?' : '&';
for (var key in data) {
queryString += key + '=' + data[key] + '&';
}
queryString += 'callback=' + cbFuncName;
var script = document.createElement('script');
script.src = url + queryString;
document.body.appendChild(script);
}
export default jsonp

在新建一个config.js 用来存放一些配置信息

const apiServer = 'https://api.douban.com/v2/movie/';
export default { apiServer }

接着在新建一个focus.js 用来左边导航栏获取焦点

添加以下代码
import Vue from 'vue'
var focus = {};
focus.install = function () {
Vue.directive('focus', function (el, binding) {
var server = binding.value.server;
var aLink = el.children[0].href;
var link = /^((http)?:\/\/)[\w]+:+[\d]+\/\W+([\w]+)?\/\w/;
var val = (aLink.match(link))[3];
el.className = '';
if (val == server) {
el.className = 'active';
}
})
}
export default focus;

然后来到main.js中 引用vue-router 和引用刚才的focus.js和配置vue-router

import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import movielist from './components/movielist.vue'
import focus from './js/focus' Vue.use(VueRouter)
Vue.use(focus)
var routes = [{
path: '/:server/:page', component: movielist
},
{ path: '*', redirect:'/in_theaters/0' }]
var router = new VueRouter({
routes
})
new Vue({
el: '#app',
router,
render: h => h(App)
})

到这边页面基本成型了

回到命令行 继续执行该命令
npm run dev
 

项目源码已经分享到github上
https://github.com/lentoo/vue-movie
欢迎Star
 

公众号

欢迎关注我的公众号“码上开发”,每天分享最新技术资讯。关注获取最新资源

基于vue2.0的一个豆瓣电影App的更多相关文章

  1. 基于Bootstrap+angular的一个豆瓣电影app

    1.搭建项目框架 npm初始化项目 npm init -y //按默认配置初始化项目 安装需要的第三方库 npm install bootstrap angular angular-route --s ...

  2. 基于vue2.0的一个系统

    前言 这是一个用vue做的单页面管理系统,这里只是介绍架子搭建思路 前端架构 沿用Vue全家桶系列开发,主要技术栈:vue2.x+vue-router+vuex+element-ui1.x+axios ...

  3. 基于vue2.0的一个分页组件

    分页组件在项目中经常要用到之前一直都是在网上找些jq的控件来用(逃..),最近几个项目用上vue了项目又刚好需要一个分页的功能.于是百度发现几篇文章介绍的实在方式有点复杂, 没耐心看自己动手造轮子写了 ...

  4. 基于vue2.0的在线电影APP,

    基于vue2.0构建的在线电影网[film],webpack + vue + vuex + vue-loader + keepAlive + muse-ui + cordova 全家桶,cordova ...

  5. 基于vue2.0的分页组件开发

    今天安排的任务是写基于vue2.0的分页组件,好吧,我一开始是觉得超级简单的,但是越写越写不出来,写的最后乱七八糟的都不知道下句该写什么了,所以重新捋了思路,小结一下- 首先写组件需要考虑: 要从父组 ...

  6. 基于vue2.0打造移动商城页面实践 vue实现商城购物车功能 基于Vue、Vuex、Vue-router实现的购物商城(原生切换动画)效果

    基于vue2.0打造移动商城页面实践 地址:https://www.jianshu.com/p/2129bc4d40e9 vue实现商城购物车功能 地址:http://www.jb51.net/art ...

  7. 基于vue2.0前端组件库element中 el-form表单 自定义验证填坑

    eleme写的基于vue2.0的前端组件库: http://element.eleme.io 我在平时使用过程中,遇到的问题. 自定义表单验证出坑: 1: validate/resetFields 未 ...

  8. vue-swiper 基于Vue2.0开发 轻量、高性能轮播插件

    vue-swiper 基于 Vue2.0 开发,基本满足大部分功能 轻量.高性能轮播插件.目前支持 无缝衔接自动轮播.无限轮播.手势轮播 没有引入第三方库,原生 js 封装,打包之后只有 8.2KB ...

  9. 基于mykernel2.0编写一个操作系统内核

    基于mykernel2.0编写一个操作系统内核 一. 实验准备 详细要求 基于mykernel 2.0编写一个操作系统内核 按照https://github.com/mengning/mykernel ...

随机推荐

  1. 如何通过 WebP 兼容减少图片资源大小

    作者:学军又拍云 CDN 服务公测 WebP 自适应功能,为客户减少图片资源大小.本文我们将一起来阐述WebP兼容的来龙去脉. 前言我们知道,理想的网页应该在 1 秒内打开,而在页面的整体大小中,图片 ...

  2. 用scikit-learn学习LDA主题模型

    在LDA模型原理篇我们总结了LDA主题模型的原理,这里我们就从应用的角度来使用scikit-learn来学习LDA主题模型.除了scikit-learn,  还有spark MLlib和gensim库 ...

  3. 弹出框插件layer使用

    layer是一款近年来备受青睐的web弹层组件,她具备全方位的解决方案,致力于服务各水平段的开发人员,您的页面会轻松地拥有丰富友好的操作体验. 插件官方地址:http://layer.layui.co ...

  4. firstChild,lastChild,nextSibling,previousSibling & 兼容性写法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. poj2069

    poj2069 题意 求一个覆盖所有点的最小球体的半径.即求空间内一点到所有点的距离的最大值最小的点. 分析 模拟退火算法,但这道题竟然不用随机函数就能过了,主要体现了算法的渐近收敛性, 起始点随意取 ...

  6. Javascript加载执行顺序

    本文主要内容 一.不同位置的script标签执行顺序 二.document.ready和window.onload的区别 一.不同位置的script标签执行顺序 整个加载的过程从解析头部开始,比如ht ...

  7. react 基础

    一.组件 函数式定义的无状态组件 es5原生方式React.createClass定义的组件 es6形式的extends React.Component定义的组件 React.Component是以E ...

  8. NodeJS+Express+MongoDB 简单个人博客系统【Study笔记】

    Blog 个人博客系统 iBlog是在学习NodeJs时候一个练手项目Demo 系统支持用户注册/登录,内容文章查看,评论,后台管理(定制显示的分类版块,进行文章内容添加)超级管理员还可进行用户管理等 ...

  9. 工程师倾情奉献-Win7 ISO 精简操作说明

    1.前提条件 a)本文档内容只适用于32bit win7 install ISO,其它OS不能保证兼容 b)示范文件为win7-ultimate-rtm-32-en-us-rdvd.iso 2.准备待 ...

  10. 在ASP.Net MVC 中如何实现跨越Session的分布式TempData

    Hi,guys!Long time no see! 1.问题的引出 我相信大家在项目中都使用过TempData,TempData是一个字典集合,一般用于两个请求之间临时缓存数据或者页面之间传递消息.也 ...