Skip to content

Instantly share code, notes, and snippets.

View Kelin2025's full-sized avatar
🤚
Came back with more Open-Source stuff

Anton Kosykh Kelin2025

🤚
Came back with more Open-Source stuff
View GitHub Profile
@Kelin2025
Kelin2025 / component.vue
Created March 3, 2017 17:12
i18n for Vue.js + Vuex
<template lang="pug">
div.list
span {{translate('global.lang')}}
label(v-for="lang in available").item
input(type="radio",v-model="current",:value="lang")
img(:src="icon(lang)",:class="{active: lang === current}")
</template>
<script>
export default {
import { required, numeric } from 'vuelidate/lib/validators'
import { buildFromValidator } from '@/common/utils/forms'
const form = {
name: { required },
weapon: { required },
price: { numeric },
image: { required },
nested: {
item: { required, numeric }
@Kelin2025
Kelin2025 / example.js
Last active August 14, 2017 13:54
Problem of vuelidate
export default {
data: () => ({
form: {
name: null,
surname: null,
age: null
}
}),
validations: {
form: {
@Kelin2025
Kelin2025 / example.js
Created August 14, 2017 13:55
Vuelidate-forms demo
export default {
forms: {
form: {
name: { required },
surname: { required },
age: {
required,
min: value => value >= 18
},
// That one will have a default value
@Kelin2025
Kelin2025 / example.js
Last active May 8, 2022 04:14
Apicase example
import { Container } from 'apicase'
// Declare headers
const headers = () => ({
token: localStorage.getItem('token')
})
// Declare services
const services = {
hello: {
@Kelin2025
Kelin2025 / example.js
Created August 14, 2017 14:17
Vuelidate-forms methods
this.$form('test').reset() // Reset previous state for form
this.$form('test').validate() // Call $touch() + return !$invalid
@Kelin2025
Kelin2025 / example.vue
Last active August 14, 2017 14:21
Vue-apicase example
<template>
<div>
<div v-if="apis.hello.pending">Loading</div>
<div v-else>
<button @click="$api.go('hello')">Hello</button>
</div>
</div>
</template>
<script>
@Kelin2025
Kelin2025 / example.vue
Created August 14, 2017 14:25
Vuelidate-apicase-connect example
<template>
<form @submit.prevent="$form('testForm').submit('hello')">
<h2> Vuelidate-forms + Vue-Apicase demo</h2>
<label> My name is </label>
<input
type="text"
v-model="test.name"
@input="$v.test.name.$touch"
:class="{ invalid: $v.test.name.$invalid && $v.test.name.$dirty }"
placeholder="Enter your name"
@Kelin2025
Kelin2025 / boilerplate-code-example.js
Last active August 22, 2017 18:29
Example of incorrect API calls
/* Example of boilerplate api call */
let res = await get('/posts')
if (res.success) {
/*
Place data somewhere, success alert etc.
I really feel sorry for people
who still writes so in every call
just copy-paste and don't worry about
And I pretty sure that most of you will say
"Wtf do you talk? There is no another way"
@Kelin2025
Kelin2025 / 1.noapicase.js
Last active May 8, 2022 04:12
API declaration with and without Apicase
import axios from './axios-custom'
export const foo = () => axios.get('/foo/bar/')
export const products = {
get: id =>
axios.get(`/products/${id}`),
save: (data, id = null) =>