Skip to content

Instantly share code, notes, and snippets.

@mdunbavan
Created February 10, 2017 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdunbavan/9412e23bb89e929ce3b1f4d49d217baa to your computer and use it in GitHub Desktop.
Save mdunbavan/9412e23bb89e929ce3b1f4d49d217baa to your computer and use it in GitHub Desktop.
vue js routes
const PeopleListing = ('people-listing', {
template: '#people-listing-template',
delimiters: ['${', '}'],
data: function() {
return {
products: []
}
},
mounted: function() {
this.getAllProducts();
},
methods: {
getAllProducts: function(){
this.$http.get('/collections/homepage/products.json').then(function (response) {
$.each(response.data.products, function(key, value) {
var product = value;
this.products.push(product);
}.bind(this));
}.bind(this), function (response) {
console.log('error getting beers from the pivot table');
});
}
},
props: ['people-listing']
});
const ProductDetail = ('product-detail', {
template: '#product-detail-template',
delimiters: ['${', '}'],
created () {
this.fetchData()
},
watch: {
'$route': 'fetchData'
},
methods: {
fetchData () {
this.error = this.product = null
getPost(this.$route.params.handle, (err, post) => {
this.loading = false
if (err) {
this.error = err.toString()
} else {
this.product = product
}
})
}
}
});
const router = new VueRouter({
mode: 'history',
routes: [
{path: '/', component: PeopleListing},
{name: 'product', path: '/products/:handle', component: ProductDetail }
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment