Skip to content

Instantly share code, notes, and snippets.

View cn-2k's full-sized avatar
🎯
Focusing

cn-2k cn-2k

🎯
Focusing
View GitHub Profile
@cn-2k
cn-2k / date-picker.vue
Created October 5, 2021 01:37
V-Calendar date picker
<template>
<div>
<div class="date-examples">
<div>
<DatePicker
v-model="date"
:is-range="isRange"
:model-config="modelConfig"
is-required
>
@cn-2k
cn-2k / axios.js
Last active November 17, 2021 12:17
Axios request
// Making post request using axios (with headers too)
axios
.post('localhost', payload, {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
})
.then(function (response) {
console.log(response)
@cn-2k
cn-2k / vue-img-upload.vue
Created November 17, 2021 12:13
Upload image with Axios + Vue 3
<template>
<input type="file" @change="handleFileUpload($event)"/>
</template>
<script>
import axios from 'axios'
import { reactive, toRefs } from 'vue'
export default {
@cn-2k
cn-2k / img-upload.vue
Created November 18, 2021 11:32
Upload image with form data + Vue and Axios
// It's just a piece of code.
const token = VueCookieNext.getCookie('token')
let formData = new FormData()
const state = reactive({
photo: null,
})
formData.append('name', fullName.value)
@cn-2k
cn-2k / multiselect.vue
Last active November 25, 2021 14:31
@vueform/multiselect - state/city
<p class="mb-1 text-brand-mainDark">
Select state | {{selectedState}}
</p>
<Multiselect
placeholder="Select state"
:minChars="1"
:required="true"
autocomplete="undefined"
v-model="selectedState"
@cn-2k
cn-2k / compare-arrays.js
Created December 6, 2021 13:59
Comparing two arrays of object
// comparing by id
const output = yourFirstArray.filter((item1) => !yourSecondArray.some((item2) => item1.id == item2.id))
console.log(output)
// or
// attention: "id" is a variable of yourFirstArray filter method
const output = yourFirstArray.filter(({ id }) => !yourSecondArray.find(item => item.id == id));
console.log(output);
const multiValue = ref()
const groups = reactive([])
groups = datas.roles.map((item) => ({
value: item.name,
label: item.name,
}))
<p>{{ multiValue }}</p>
<multiselect
@cn-2k
cn-2k / torefs.vue
Created January 13, 2022 20:12
Vue 3 toRefs in script setup use case
const searchEntities = ref('')
const searchActions = ref('')
const loadingTable = ref(false)
const loadingRegister = ref(false)
const singleTable = ref(null)
const newEntity = ref(false)
const entityName = ref('')
const newAction = ref(false)
const actionName = ref('')
@cn-2k
cn-2k / dataToParent.vue
Created February 2, 2022 15:52
Watch + Emit - Vue 3 (C.A)
// first of all: props are for parent -> child and we can use emit for child -> parent
// parent-component.vue
<card-stats
@goalReachedPercentage="getReachedGoalValue"
/>
const getReachedGoalValue = (percent) => {
datas.indicatorGoalPercentage.push(percent)
@cn-2k
cn-2k / date-picker.vue
Created March 18, 2022 12:51
Date Picker (V-Calendar) Component
<template>
<DatePicker
v-model="range"
:model-config="modelConfig"
:startDate="startDate"
:endDate="endDate"
is-range
is-required
color="green"
>