Last active
February 7, 2017 20:13
-
-
Save mdunbavan/65c9ad008ef06bc1c9058d76507e864e to your computer and use it in GitHub Desktop.
Vuejs base
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
<section id="home-container" class="parralex-scroll"> | |
<router-view></router-view> | |
</section> |
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
Vue.use(VueResource); | |
Vue.use(VueRouter); | |
//import PeopleListing from '../assets/ProductList.js'; | |
//import ProductSingle from '../templates/ProductSingle.vue'; | |
// const Home = { template: '<div>home</div>' } | |
const PeopleListing = ('people-listing', { | |
template: '#people-listing-template', | |
// data: { | |
// products: [] | |
// }, | |
data: function() { | |
return { | |
products: [] | |
} | |
}, | |
mounted: function() { | |
this.getAllProducts(); | |
}, | |
methods: { | |
getAllProducts: function(){ | |
this.$http.get('/collections/homepage/products.json').then(function (response) { | |
$.each(response.data, function(key, value) { | |
this.products.push(value.id); | |
}.bind(this)); | |
}.bind(this), function (response) { | |
console.log('error getting beers from the pivot table'); | |
}); | |
} | |
}, | |
props: ['people-listing'] | |
}); | |
const router = new VueRouter({ | |
mode: 'history', | |
base: window.location.href, | |
routes: [ | |
{path: '/', component: PeopleListing} | |
] | |
}); | |
new Vue({ | |
router, | |
el: "#home-container", | |
delimiters: ['${', '}'], | |
data: { | |
nextPage: 0, | |
showSpinner: 1, | |
products: [], | |
pages: [], | |
blogs: [], | |
}, | |
methods: { | |
// Load nav in case we need to preload it later | |
// on for speed | |
loadNav: function() { | |
this.showSpinner = 1; | |
this.$http.get('/collections/homepage/products.json').then(function(data) { | |
this.products = this.products.concat(data.body.products); | |
}); | |
}, | |
prerenderLink: function(e) { | |
var head = document.getElementsByTagName("head")[0]; | |
var refs = head.childNodes; | |
ref = refs[ refs.length - 1]; | |
var elements = head.getElementsByTagName("link"); | |
Array.prototype.forEach.call(elements, function(el, i) { | |
if (("rel" in el) && (el.rel === "prerender")) | |
el.parentNode.removeChild(el); | |
}); | |
var prerenderTag = document.createElement("link"); | |
prerenderTag.rel = "prerender"; | |
prerenderTag.href = e.currentTarget.href; | |
ref.parentNode.insertBefore(prerenderTag, ref); | |
}, | |
}, | |
created: function() { | |
this.fetchProducts(); | |
this.fetchPages(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment