Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. Vue.component('post-list', {
  2. template: `
  3. <div>{{ posts }} </div>
  4. <div class="post" v-for="post in posts" :key="post.date">
  5. <h2>{{ post.name }}</h2>
  6. <div class="info">Date: {{ post.date }}</div>
  7. </div>
  8. `,
  9. data: function() {
  10. return {
  11. posts: [
  12. {
  13. name: "Hello World",
  14. filename: "hello-world",
  15. date: "2016-12-1"
  16. }
  17. ]
  18. };
  19. }
  20. })
  21.  
  22. // base = '/blog/'
  23. const base = document.querySelector('base').getAttribute('href');
  24.  
  25. const app = new Vue({
  26. el: '#content',
  27. data: function() {
  28. return {current_path: window.location.pathname};
  29. },
  30. computed:{
  31. view_component: function() {
  32. var path = this.current_path.replace(base, '');
  33. if(!path.startsWith('/')) {
  34. path = '/' + path;
  35. }
  36. const route_re = new RegExp('(/[^/]*).*');
  37. const route_name = route_re.exec(path)[1];
  38. return route_name;
  39. }
  40. },
  41. render: function(h) {
  42. if(this.view_component == "/") {
  43. return h('post-list');
  44. } else {
  45. return h('h2', 'Not Found');
  46. }
  47. }
  48.  
  49. });
  50.  
  51. window.addEventListener('popstate', function(){
  52. app.current_path = window.location.pathname
  53. });
  54. // vim:ai:et:sta:ts=4:sts=4:sw=4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement