Created
April 27, 2017 07:38
-
-
Save cherry-geqi/68b3b83491394851f94d8364ab099a83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<script src="//cdn.jsdelivr.net/vue/2.2.6/vue.min.js"></script> | |
<script src="//cdn.jsdelivr.net/vue.router/2.5.2/vue-router.min.js"></script> | |
<script src="//cdn.jsdelivr.net/axios/0.16.1/axios.min.js"></script> | |
<style> | |
.user { | |
height: 200px; | |
line-height: 200px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="app"> | |
<router-view></router-view> | |
</div> | |
<script> | |
const Home = { | |
template: '<div><p class="user" v-for="user in users" @click="navigate">{{ user.login }}</p></div>', | |
data() { | |
return { | |
users: [], | |
}; | |
}, | |
created() { | |
axios.get('https://api.github.com/users').then(({ data: users }) => { | |
this.users = users; | |
}); | |
}, | |
methods: { | |
navigate() { | |
this.$router.push('/detail'); | |
} | |
} | |
}; | |
const Detail = { template: '<h1>Detail</h1>'}; | |
const router = new VueRouter({ | |
routes: [ | |
{ path: '/', redirect: '/home' }, | |
{ path: '/home', component: Home }, | |
{ path: '/detail', component: Detail } | |
] | |
}); | |
Vue.use(VueRouter); | |
new Vue({ | |
el: '#app', | |
router | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment