Make a headless CMS eCommerce front-end for Vue.js, Nuxt.js and Snipcart (ssr)
Written by Even Westvang
Missing Image!
We’ve been hearing so many nice things about Vue.js. So to get to know it better we though it would be good to build a more complete front-end for it.
Also, the same week Sanity launched the kind folks over at Snipcart built a demo using us as the content backend for a simple e-commerce app.
So we thought we should repay the favor and just a few days ago we added to our install a headless localized e-commerce example as one of the defaults we offer when you install Sanity. So we therefore thought we should, nay must, make an e-commerce front-end for Vue.js, Nuxt.js and Snipcart backed by Sanity.io that you can host as a statically generated build on Netlify.
Who is Sanity.io?
That's us. Sanity.io is a cloud hosted content store with a powerful graph oriented query language. The editing environment, somewhat generically named Sanity Studio, is an open source MIT licensed client side application that you can customize to your liking in JavaScript and React.js. Setup takes a two minutes. Give it a try.
What’s Vue.js anyway?
Vue.js is a flexible and lightweight library for building web interfaces with Javascript. Similarly to React.js it offers a virtual DOM and reactive components. Some people like it for it’s brevity. Our in-house designer, Kristoffer, likes the way the people behind it think – how it feels clear and natural and has affordances for the everyday needs of people who build web apps.
And what’s a Nuxt.js?
Inspired by Next.js, Nuxt is a framework for creating universal Vue.js applications. It ships with all the stuff you probably will want, preconfigured: routing, async data, middleware, layouts, etc.
Who is Snipcart?
Snipcart is a full featured, low-threshold shopping cart that lets you add e-commerce functionality to your website by including their javascript and a few data attributes to your pages. This is how we were all told the future would work.
Run it!
We’ve got a sliding scale of getting involved here.
- Medium: Wander off and click at the example - we've hosted it on Netlify (see instruction below for building a static site). There's also Zeit now as well.
- Large: Install the Vue.js front-end yourself, with our canned data. The readme has the instructions. Do make sure you have a recent Node installed and don’t change the port numbers as we’re picky about CORS origins.
- Supersize me: Spend 5 minutes setting up Sanity to power it all with your own product data.
Yes, in five minutes you can add fields or get back at the vikings by removing Norwegian as an available language as well as build your own product database. With variants! Hierarchical categories! Vendors! Tags! Gah!
The readme for the project has the instructions for this as well. All four bullet points of it.
All batteries are included and instructions for deploying on Zeit's Now (type now
) as well as Netlify. Fly little rocket ship, fly. 🚀
A tiny caveat or two
Yes, we didn’t implement totally ALL the things implied by the schema. We would maybe have said these were left as exercises to the reader if we weren't afraid of looking super obnoxious.
The localization is locked to English when it should perhaps be reading Accept-Language
, yet again your implementation will vary on your hosting. Also: there aren't any product variants displayed. Maybe your store doesn't have any. Maybe the sweaters you're selling are all a tepid cyan. If they're not, we'll gladly accept a pull request for the display of variants!