fetching blogs and articles
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
<template>
|
||||||
|
<div class="columns">
|
||||||
|
<div v-for="article in articles" :key="article.id" class="column is-one-third">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-image">
|
||||||
|
<figure class="image is-4by3">
|
||||||
|
<img :src="article.image.src" :alt="product.images[0].altText">
|
||||||
|
</figure>
|
||||||
|
</div>
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="media">
|
||||||
|
<div class="media-content">
|
||||||
|
<p class="title is-4">
|
||||||
|
{{ product.title }}
|
||||||
|
</p>
|
||||||
|
<p class="subtitle is-6">
|
||||||
|
{{ product.variants[0].price }} €
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<b-button
|
||||||
|
tag="router-link"
|
||||||
|
:to="'/products/' + product.handle"
|
||||||
|
type="is-primary"
|
||||||
|
>
|
||||||
|
See
|
||||||
|
</b-button>
|
||||||
|
<b-button
|
||||||
|
type="is-primary"
|
||||||
|
icon-left="cart"
|
||||||
|
@click="addToCart(product.variants[0].id, 1)"
|
||||||
|
>
|
||||||
|
Buy
|
||||||
|
</b-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import cartMixins from '../mixins/cartMixins'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'ProductCardList',
|
||||||
|
mixins: [cartMixins],
|
||||||
|
props: {
|
||||||
|
products: {
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
+21
-12
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<b-navbar>
|
<b-navbar>
|
||||||
<template slot="brand">
|
<template slot="brand">
|
||||||
<b-navbar-item tag="router-link" to="/">
|
<b-navbar-item tag="a" href="/">
|
||||||
<img
|
<img
|
||||||
src="https://raw.githubusercontent.com/buefy/buefy/dev/static/img/buefy-logo.png"
|
src="https://raw.githubusercontent.com/buefy/buefy/dev/static/img/buefy-logo.png"
|
||||||
alt="Lightweight UI components for Vue.js based on Bulma"
|
alt="Lightweight UI components for Vue.js based on Bulma"
|
||||||
@@ -10,17 +10,27 @@
|
|||||||
</template>
|
</template>
|
||||||
<template slot="start">
|
<template slot="start">
|
||||||
<b-navbar-item
|
<b-navbar-item
|
||||||
tag="router-link"
|
tag="nuxt-link"
|
||||||
to="/products"
|
to="/products"
|
||||||
>
|
>
|
||||||
Products
|
Products
|
||||||
</b-navbar-item>
|
</b-navbar-item>
|
||||||
<b-navbar-item
|
<b-navbar-dropdown label="Blog">
|
||||||
tag="router-link"
|
<b-navbar-item
|
||||||
to="/blog"
|
tag="a"
|
||||||
>
|
href="/blog"
|
||||||
Blog
|
>
|
||||||
</b-navbar-item>
|
All
|
||||||
|
</b-navbar-item>
|
||||||
|
<b-navbar-item
|
||||||
|
v-for="blog in blogs"
|
||||||
|
:key="blog.id"
|
||||||
|
tag="a"
|
||||||
|
:href="`/blog/${blog.handle}`"
|
||||||
|
>
|
||||||
|
{{ blog.title }}
|
||||||
|
</b-navbar-item>
|
||||||
|
</b-navbar-dropdown>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template slot="end">
|
<template slot="end">
|
||||||
@@ -41,13 +51,12 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'TheNavbar',
|
name: 'TheNavbar',
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
cardCount () {
|
cardCount () {
|
||||||
return this.$store.state.checkout.lineItems.length
|
return this.$store.state.checkout.lineItems.length
|
||||||
|
},
|
||||||
|
blogs () {
|
||||||
|
return this.$store.state.blogs
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
+8
-1
@@ -12,7 +12,14 @@
|
|||||||
<script>
|
<script>
|
||||||
import TheNavbar from '../components/TheNavbar'
|
import TheNavbar from '../components/TheNavbar'
|
||||||
export default {
|
export default {
|
||||||
components: { TheNavbar }
|
components: { TheNavbar },
|
||||||
|
asyncData ({ $shopify }) {
|
||||||
|
return $shopify.collection.fetchAllWithProducts().then((collections) => {
|
||||||
|
return {
|
||||||
|
collections
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ export default {
|
|||||||
/*
|
/*
|
||||||
** Customize the progress-bar color
|
** Customize the progress-bar color
|
||||||
*/
|
*/
|
||||||
loading: { color: '#fff' },
|
loading: { color: '#00d1b2' },
|
||||||
/*
|
/*
|
||||||
** Global CSS
|
** Global CSS
|
||||||
*/
|
*/
|
||||||
|
|||||||
+13
-1
@@ -1,12 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<h1>Blog</h1>
|
<h1>Blog</h1>
|
||||||
|
{{ articles }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'Index'
|
name: 'Index',
|
||||||
|
asyncData ({ app }) {
|
||||||
|
return app.$axios.get('https://home-deco35.myshopify.com/admin/api/2020-01/articles.json', {
|
||||||
|
headers: {
|
||||||
|
'X-Shopify-Access-Token': '99804a726edfba831c6671c3b66f413a'
|
||||||
|
}
|
||||||
|
}).then((response) => {
|
||||||
|
return {
|
||||||
|
articles: response.data
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,12 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<hr class="hr" />
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<h2 class="is-2">Products in this collection</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<product-card-list
|
<product-card-list
|
||||||
@@ -37,7 +43,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ProductCardList from '../../../components/productCardList'
|
import ProductCardList from '../../../components/ProductCardList'
|
||||||
export default {
|
export default {
|
||||||
layout: 'noContainer',
|
layout: 'noContainer',
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
+20
-3
@@ -44,13 +44,30 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
layout: 'noContainer',
|
layout: 'noContainer',
|
||||||
asyncData ({ $shopify }) {
|
asyncData ({ app }) {
|
||||||
return $shopify.collection.fetchAllWithProducts().then((collections) => {
|
return app.$axios.get('https://home-deco35.myshopify.com/admin/api/2020-01/blogs.json', {
|
||||||
|
headers: {
|
||||||
|
'X-Shopify-Access-Token': '99804a726edfba831c6671c3b66f413a'
|
||||||
|
}
|
||||||
|
}).then((response) => {
|
||||||
return {
|
return {
|
||||||
collections
|
blogs: response.data.blogs
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
collections: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.$shopify.collection.fetchAllWithProducts().then((collections) => {
|
||||||
|
this.collections = collections
|
||||||
|
})
|
||||||
|
this.$store.commit('setBlogs', this.blogs)
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Blog: ', this.blogs)
|
||||||
|
},
|
||||||
beforeUpdate () {
|
beforeUpdate () {
|
||||||
if (typeof this.$store.state.checkout.id === 'undefined') {
|
if (typeof this.$store.state.checkout.id === 'undefined') {
|
||||||
this.$shopify.checkout.create().then((checkout) => {
|
this.$shopify.checkout.create().then((checkout) => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import cartMixins from '../../mixins/cartMixins'
|
import cartMixins from '../../mixins/cartMixins'
|
||||||
import ProductCardList from '../../components/productCardList'
|
import ProductCardList from '../../components/ProductCardList'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Index',
|
name: 'Index',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
products: [],
|
products: [],
|
||||||
|
blogs: [],
|
||||||
checkout: {
|
checkout: {
|
||||||
lineItems: []
|
lineItems: []
|
||||||
}
|
}
|
||||||
@@ -11,5 +12,8 @@ export const mutations = {
|
|||||||
},
|
},
|
||||||
setCheckout (state, data) {
|
setCheckout (state, data) {
|
||||||
state.checkout = data
|
state.checkout = data
|
||||||
|
},
|
||||||
|
setBlogs (state, data) {
|
||||||
|
state.blogs = data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user