Skip to content

Commit

Permalink
+ router & photo pages
Browse files Browse the repository at this point in the history
  • Loading branch information
lyyourc committed May 3, 2017
1 parent 7a6f534 commit 84d6c7c
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 21 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
},
"dependencies": {
"axios": "^0.15.3",
"vue": "^2.2.1"
"justified-layout": "^2.1.0",
"vue": "^2.2.1",
"vue-router": "^2.5.3"
},
"devDependencies": {
"babel-core": "^6.0.0",
Expand All @@ -23,7 +25,7 @@
"html-webpack-plugin": "^2.28.0",
"vue-loader": "^11.1.4",
"vue-template-compiler": "^2.2.1",
"webpack": "^2.2.0",
"webpack": "^2.4.1",
"webpack-bundle-analyzer": "^2.3.1",
"webpack-dev-server": "^2.2.0"
}
Expand Down
12 changes: 9 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<template>
<div id="app">
<emoji></emoji>
<navbar></navbar>
<router-view class="main"></router-view>
</div>
</template>

<script>
import Emoji from './pages/Emoji.vue'
import Navbar from './components/Navbar.vue'
export default {
name: 'app',
components: { Emoji },
components: { Navbar },
}
</script>

Expand All @@ -30,4 +32,8 @@ body {
align-items: center;
justify-content: center;
}
.main {
flex: 1;
}
</style>
53 changes: 53 additions & 0 deletions src/components/Navbar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<nav>
<ul>
<li v-for="nav in navs">
<router-link :to="nav.path" exact>
{{ nav.name }}
</router-link>
</li>
</ul>
</nav>
</template>

<script>
export default {
data() {
return {
navs: [
{ name: 'Home', path: '/' },
{ name: 'Photos', path: '/photos' },
],
}
},
}
</script>

<style scoped>
nav {
display: flex;
justify-content: center;
color: #000;
font-size: 2rem;
margin-top: 20px;
}
ul {
list-style: none;
display: flex;
margin: 0;
}
li {
margin: 0 1rem;
}
a {
color: #abcedf;
text-decoration: none;
}
a.router-link-active {
text-decoration: underline;
}
</style>
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Vue from 'vue'
import App from './App.vue'
import router from './router'

new Vue({
router,
el: '#app',
render: h => h(App)
})
2 changes: 2 additions & 0 deletions src/pages/Emoji.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export default {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 100px;
text-align: center;
}
</style>
78 changes: 78 additions & 0 deletions src/pages/Photos.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<template>
<div :style="{ height: `${layoutGeometry.containerHeight}px` }">
<section v-for="(box, i) in layoutGeometry.boxes"
:style="{
width: `${box.width}px`,
height: `${box.height}px`,
top: `${box.top}px`,
left: `${box.left}px` }">
<img :src="imgs[i].url">
</section>
</div>
</template>

<script>
import axios from 'axios'
import justifiedLayout from 'justified-layout'
import MagicBtn from '../components/MagicBtn.vue'
export default {
components: { MagicBtn },
data () {
return {
imgs: [],
layoutGeometry: {
boxes: [],
},
}
},
created() {
this.fetchImages()
},
methods: {
fetchImages() {
try {
axios.get('https://www.reddit.com/r/funny.json')
.then(res => res.data.data.children)
.then(posts => posts.map(p => p.data.preview.images[0].source))
.then(imgs => Promise.all(imgs.map(i => this.verifyImg(i))))
.then(imgs => imgs.filter(i => i.invalid !== true))
.then(imgs => {
this.imgs = imgs
const sizes = imgs.map(img => img.width / img.height)
this.layoutGeometry = justifiedLayout(sizes)
})
} catch (err) {
console.error(err)
}
},
verifyImg(image) {
return new Promise((resolve, reject) => {
const img = new Image()
img.src = image.url
img.onload = () => resolve(image)
img.onerror = () =>
resolve(Object.assign({}, image, { invalid: true }))
})
},
},
}
</script>

<style styled>
div {
position: relative;
width: 1060px;
margin: 0 auto;
}
section {
position: absolute;
}
img {
height: 100%;
width: 100%;
}
</style>
24 changes: 24 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Vue from 'vue'
import VueRouter from 'vue-router'

import Emoji from './pages/Emoji.vue'
import Photos from './pages/photos.vue'


Vue.use(VueRouter)


export default new VueRouter({
mode: 'history',

routes: [
{
path: '/',
component: Emoji,
},
{
path: '/photos',
component: Photos,
},
],
})
55 changes: 39 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ acorn-dynamic-import@^2.0.0:
dependencies:
acorn "^4.0.3"

acorn@^4.0.11, acorn@^4.0.3, acorn@^4.0.4:
acorn@^4.0.11, acorn@^4.0.3:
version "4.0.11"
resolved "http://registry.npm.taobao.org/acorn/download/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0"

acorn@^5.0.0:
version "5.0.3"
resolved "http://registry.npm.taobao.org/acorn/download/acorn-5.0.3.tgz#c460df08491463f028ccb82eab3730bf01087b3d"

ajv-keywords@^1.1.1:
version "1.5.1"
resolved "http://registry.npm.taobao.org/ajv-keywords/download/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c"
Expand Down Expand Up @@ -2192,7 +2196,7 @@ json3@^3.3.2:
version "3.3.2"
resolved "http://registry.npm.taobao.org/json3/download/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1"

json5@^0.5.0:
json5@^0.5.0, json5@^0.5.1:
version "0.5.1"
resolved "http://registry.npm.taobao.org/json5/download/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

Expand All @@ -2209,6 +2213,12 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.3.6"

justified-layout@^2.1.0:
version "2.1.0"
resolved "http://registry.npm.taobao.org/justified-layout/download/justified-layout-2.1.0.tgz#f69be6f5b19a6214ca517b884637be9ffdc0eb76"
dependencies:
merge "1.2.0"

kind-of@^3.0.2:
version "3.1.0"
resolved "http://registry.npm.taobao.org/kind-of/download/kind-of-3.1.0.tgz#475d698a5e49ff5e53d14e3e732429dc8bf4cf47"
Expand Down Expand Up @@ -2347,6 +2357,10 @@ merge-descriptors@1.0.1:
version "1.0.1"
resolved "http://registry.npm.taobao.org/merge-descriptors/download/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"

merge@1.2.0:
version "1.2.0"
resolved "http://registry.npm.taobao.org/merge/download/merge-1.2.0.tgz#7531e39d4949c281a66b8c5a6e0265e8b05894da"

methods@~1.1.2:
version "1.1.2"
resolved "http://registry.npm.taobao.org/methods/download/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
Expand Down Expand Up @@ -3434,10 +3448,14 @@ sort-keys@^1.0.0:
dependencies:
is-plain-obj "^1.0.0"

source-list-map@^0.1.4, source-list-map@~0.1.7:
source-list-map@^0.1.4:
version "0.1.8"
resolved "http://registry.npm.taobao.org/source-list-map/download/source-list-map-0.1.8.tgz#c550b2ab5427f6b3f21f5afead88c4f5587b2106"

source-list-map@^1.1.1:
version "1.1.1"
resolved "http://registry.npm.taobao.org/source-list-map/download/source-list-map-1.1.1.tgz#1a33ac210ca144d1e561f906ebccab5669ff4cb4"

source-map-support@^0.4.2:
version "0.4.14"
resolved "http://registry.npm.taobao.org/source-map-support/download/source-map-support-0.4.14.tgz#9d4463772598b86271b4f523f6c1f4e02a7d6aef"
Expand Down Expand Up @@ -3654,7 +3672,7 @@ type-is@~1.6.14:
media-typer "0.3.0"
mime-types "~2.1.13"

uglify-js@2.8.x, uglify-js@^2.7.5:
uglify-js@2.8.x, uglify-js@^2.8.5:
version "2.8.14"
resolved "http://registry.npm.taobao.org/uglify-js/download/uglify-js-2.8.14.tgz#25b15d1af39b21752ee33703adbf432e8bc8f77d"
dependencies:
Expand Down Expand Up @@ -3791,6 +3809,10 @@ vue-loader@^11.1.4:
vue-style-loader "^2.0.0"
vue-template-es2015-compiler "^1.2.2"

vue-router@^2.5.3:
version "2.5.3"
resolved "http://registry.npm.taobao.org/vue-router/download/vue-router-2.5.3.tgz#073783f564b6aece6c8a59c63e298dc2aabfb51b"

vue-style-loader@^2.0.0:
version "2.0.4"
resolved "http://registry.npm.taobao.org/vue-style-loader/download/vue-style-loader-2.0.4.tgz#4fc19e18bf162225338aac3b17d0fd0e1cfb7439"
Expand All @@ -3813,7 +3835,7 @@ vue@^2.2.1:
version "2.2.4"
resolved "http://registry.npm.taobao.org/vue/download/vue-2.2.4.tgz#d0a3a050a80a12356d7950ae5a7b3131048209cc"

watchpack@^1.2.0:
watchpack@^1.3.1:
version "1.3.1"
resolved "http://registry.npm.taobao.org/watchpack/download/watchpack-1.3.1.tgz#7d8693907b28ce6013e7f3610aa2a1acf07dad87"
dependencies:
Expand Down Expand Up @@ -3873,25 +3895,26 @@ webpack-dev-server@^2.2.0:
webpack-dev-middleware "^1.9.0"
yargs "^6.0.0"

webpack-sources@^0.1.4:
version "0.1.5"
resolved "http://registry.npm.taobao.org/webpack-sources/download/webpack-sources-0.1.5.tgz#aa1f3abf0f0d74db7111c40e500b84f966640750"
webpack-sources@^0.2.3:
version "0.2.3"
resolved "http://registry.npm.taobao.org/webpack-sources/download/webpack-sources-0.2.3.tgz#17c62bfaf13c707f9d02c479e0dcdde8380697fb"
dependencies:
source-list-map "~0.1.7"
source-list-map "^1.1.1"
source-map "~0.5.3"

webpack@^2.2.0:
version "2.2.1"
resolved "http://registry.npm.taobao.org/webpack/download/webpack-2.2.1.tgz#7bb1d72ae2087dd1a4af526afec15eed17dda475"
webpack@^2.4.1:
version "2.4.1"
resolved "http://registry.npm.taobao.org/webpack/download/webpack-2.4.1.tgz#15a91dbe34966d8a4b99c7d656efd92a2e5a6f6a"
dependencies:
acorn "^4.0.4"
acorn "^5.0.0"
acorn-dynamic-import "^2.0.0"
ajv "^4.7.0"
ajv-keywords "^1.1.1"
async "^2.1.2"
enhanced-resolve "^3.0.0"
interpret "^1.0.0"
json-loader "^0.5.4"
json5 "^0.5.1"
loader-runner "^2.3.0"
loader-utils "^0.2.16"
memory-fs "~0.4.1"
Expand All @@ -3900,9 +3923,9 @@ webpack@^2.2.0:
source-map "^0.5.3"
supports-color "^3.1.0"
tapable "~0.2.5"
uglify-js "^2.7.5"
watchpack "^1.2.0"
webpack-sources "^0.1.4"
uglify-js "^2.8.5"
watchpack "^1.3.1"
webpack-sources "^0.2.3"
yargs "^6.0.0"

websocket-driver@>=0.5.1:
Expand Down

0 comments on commit 84d6c7c

Please sign in to comment.