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. 创建发布自己的npm包

    我们基于nodejs平台上面的npm上,可以随意下载很多npm安装包.那我们如何创建自己的npm包呢?很简单,废话少说,开始做~ 开始做之前nodejs默认是要安装的,怎么安装自行百度其他教程. 首先 ...

  2. java 1.8 动态代理源码分析

    JDK8动态代理源码分析 动态代理的基本使用就不详细介绍了: 例子: class proxyed implements pro{ @Override public void text() { Syst ...

  3. Xamarin控件使用之GridView

    [Activity(Label = "MainGridViewActivity", LaunchMode = LaunchMode.SingleTop)]//设置Activity启 ...

  4. c++字符串的输入的思考

    字符串的输入,是学习c++的一个重点,也是一个极富有细节意味的知识点,如果你不了解这些细节,你可能会在写程序时犯错而一脸懵逼不知所措. 与此同时,我们要了解c++缓冲区的概念,程序的输入都建有一个缓冲 ...

  5. [0] WCF开发下,提示HTTP 无法注册 URL 进程不具有此命名空间的访问权限

    Visual Studio以管理员的身份运行就可以了.

  6. python 标准库 -- multiprocessing

    multiprocessing 与 threading.Thread 类似 multiprocessing.Process 创建进程, 该进程可以运行用 python 编写的函数. multiproc ...

  7. 什么是nginx?

    1.nginx是一款服务器软件 2.nginx是一个高性能的HTTP和反向代理服务器: 3.nginx是一个代理邮件服务器: 4.nginx还可以实现负载均衡: nginx的优缺点: 优点:可以实现高 ...

  8. ecshop屏蔽wap功能

    用手机打开ecshop网店,就会被重定向到mobile文件夹,如果打开wap功能,就能看到wap版的网站.但现在智能手机横行,iphone.安卓可以跟电脑一样浏览和购物,这个wap功能就有点鸡肋.现在 ...

  9. 增强学习 | AlphaGo背后的秘密

    "敢于尝试,才有突破" 2017年5月27日,当今世界排名第一的中国棋手柯洁与AlphaGo 2.0的三局对战落败.该事件标志着最新的人工智能技术在围棋竞技领域超越了人类智能,借此 ...

  10. explode和implode的运用

    $kesu_list=DD('Kesu.Kesu')->kesu_list(); foreach($kesu_list[0] as $key=>$val){ $reason_id_list ...