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 / .eslintrc.cjs
Last active October 17, 2023 11:45
eslint config
module.exports = {
root: true,
env: {
node: true,
},
parser: "vue-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
ecmaVersion: 2018,
sourceType: "module",
@cn-2k
cn-2k / checkSlot.vue
Last active June 30, 2022 20:25
Check if a named slot is empty in VueJS
<template>
<div>
<nav
v-if="slots.myNamedSlot"
>
<slot name="myNamedSlot" />
</nav>
</div>
</template>
@cn-2k
cn-2k / ElementDatePicker.vue
Created May 5, 2022 20:29
My Element UI Date Picker Range in Vue 3
<template>
<div>
<Calendar
size="mini"
v-model="myDate"
:type="dataExibitionTime === 'monthly' ? 'monthrange' : dataExibitionTime === 'yearly' ? 'monthrange' : 'daterange'"
@change="setRangeDate(); someFunction(param)"
/>
</div>
</template>
@cn-2k
cn-2k / reRenderComponent.vue
Created May 3, 2022 12:37
How to re-render an component using Vue 3 w/ Composition API
<template>
<my-component :key="componentKey" />
<button @click="forceRerender">Re-render component</button>
</template>
<script setup>
import { ref } from 'vue'
import myComponent from '@/components/myComponent.vue'
// constant that'll carry our component key to be re-rendered
@cn-2k
cn-2k / el-date-picker.vue
Created March 18, 2022 16:46
el-date-picker component (Element UI)
<template>
// Component attrs
<el-date-picker
:size="props.size"
:modelValue="props.modelValue"
@change="onChange"
@update:modelValue="handleUpdate($event, value)"
:type="props.type"
range-separator="-"
@cn-2k
cn-2k / v-model-emit.vue
Created March 18, 2022 13:04
V-Model usage inside <script setup> and emit
<template>
<input
class="input"
type="text"
:placeholder="props.label"
:value="props.modelValue"
v-on:input="updateValue($event.target.value)"
/>
</template>
@cn-2k
cn-2k / v-model.vue
Created March 18, 2022 13:03
V-Model usage with <script setup> and computed
<template>
<div>
<input v-model="model">
</div>
</template>
<script setup>
import { computed } from 'vue'
const props = defineProps({
@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"
>
@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 / 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('')