Skip to content

Instantly share code, notes, and snippets.

View guruahn's full-sized avatar
🖥️
working on @habitfactory

Jeongwoo Ahn guruahn

🖥️
working on @habitfactory
View GitHub Profile
@guruahn
guruahn / custome-refs.js
Created November 29, 2022 08:28
custome refs - Persist State
export function CustomRef(value, name) {
return customRef((track, trigger) => {
return {
get() {
track();
try {
return JSON.parse(localStorage.getItem(`my_local_${name}`));
} catch (error) {
return value;
}
@guruahn
guruahn / count.js
Created November 21, 2022 12:31
before : composables/count.js
import { ref } from 'vue';
const count = ref('');
export const useCount = () => {
return {
count
};
};
@guruahn
guruahn / count.js
Created November 21, 2022 12:29
composables/count.js
import { CustomRef } from './utils/custom-refs';
const count = new CustomRef('', 'count');
export const useCount = () => {
return {
count
};
};
@guruahn
guruahn / count.vue
Created November 21, 2022 12:27
count.vue
<template>
<h2>Counter</h2>
<h3>count: {{count}}</h3>
<button @click="count--">Down</button>
<button @click="count++">Up</button>
</template>
<script setup>
const { count } = useCount();
@guruahn
guruahn / plugins-middleware.js
Created September 6, 2022 06:41
nuxt3-router-middleware
export default defineNuxtPlugin(() => {
addRouteMiddleware('router', (to, from) => {
if(!to.query.is_from){
to.query.is_from = from.query.is_from;
return navigateTo(to, { redirectCode: 301 })
}
}, { global: true })
})
@guruahn
guruahn / nuxt.config.ts
Last active August 16, 2022 11:18
nuxt3 proxy config
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
vite: {
server: {
proxy: {
"/api": {
target: "https://your-api-server.co",
changeOrigin: true,
},
<style scoped>
.example {
color: red;
}
</style>
<template>
<div class="example">hi</div>
</template>
@guruahn
guruahn / data-attribute-tracking.js
Last active January 27, 2021 03:44
tag manager - data attribute tracking
function(){
var e = {{Click Element}};
var closestEle = e.closest('[data-woo]');
return closestEle.dataset.woo;
}
@guruahn
guruahn / NewParent.vue
Created July 16, 2020 01:03
modal with dynamic vuex
<template>
<div>
<app-modal
title="This is modal"
:visible.sync="modalVisible">
<div>
This is modal body
</div>
</app-modal>
<button @click="handleClickModalSwitch">Open Modal</button>
@guruahn
guruahn / Grandpa.vue
Last active July 16, 2020 01:08
modal with dynamic vuex
<template>
<div>
<app-parent />
<button @click="handleClickModalSwitch">Open Modal</button>
</div>
</template>
<script>
import { mapActions } from "vuex";
import AppParent from "./Parent.vue";