Skip to content

Instantly share code, notes, and snippets.

@ibrunotome
Created January 21, 2021 11:30
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 ibrunotome/a76e95da9a499244ab90753fce99bc6e to your computer and use it in GitHub Desktop.
Save ibrunotome/a76e95da9a499244ab90753fce99bc6e to your computer and use it in GitHub Desktop.
<template>
<section>
<ul class="grid grid-cols-4 justify-center gap-2">
<li v-for="(post, index) in posts"
:key="post.code"
:style="`background-image: url(${post.thumbnail})`"
class="bg-cover w-full aspect-h-4 aspect-w-4 rounded-md">
<input id="selectedPosts"
v-model="selectedPosts"
:title="post.code"
:value="post.code"
class="focus:ring-purple-500 text-purple-600 border-transparent rounded-md w-full h-full opacity-75 bg-transparent"
name="selectedPosts"
type="checkbox"
@change="checkMaxLinks">
</li>
</ul>
</section>
</template>
<script>
export default {
data () {
return {
posts: [],
selectedPosts: [],
};
},
methods: {
checkMaxLinks () {
this.$nextTick(() => {
if (this.$store.maxLinks !== null && this.selectedPosts.length > this.$store.maxLinks) {
alert(this.__(`You cannot select more than ${this.$store.maxLinks} posts.`));
this.selectedPosts.pop();
}
});
},
setPosts (posts) {
const allPosts = [...this.posts, ...posts];
this.posts = [...new Set(allPosts)];
},
},
mounted () {
this.$bus.$on('UPDATE_POSTS', (media) => {
this.selectedPosts = [];
this.$store.selectedPosts = [];
this.setPosts(media);
});
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment