Skip to content

Instantly share code, notes, and snippets.

View titusdecali's full-sized avatar
🖖

Titus Decali titusdecali

🖖
View GitHub Profile
@titusdecali
titusdecali / VueTabs.vue
Last active March 2, 2020 04:10
Tabbed Section in Vue using class binding
<template>
<div id="tabs" class="container">
<div class="tabs">
<a v-on:click="activetab=1" v-bind:class="[ activetab === 1 ? 'active' : '' ]">Tab 1</a>
<a v-on:click="activetab=2" v-bind:class="[ activetab === 2 ? 'active' : '' ]">Tab 2</a>
<a v-on:click="activetab=3" v-bind:class="[ activetab === 3 ? 'active' : '' ]">Tab 3</a>
</div>
<div class="content">
@titusdecali
titusdecali / .vue-translation.js
Last active November 25, 2020 09:55
config file for vue-translation-manager
const path = require("path");
const { JSONAdapter } = require("vue-translation-manager");
module.exports = {
srcPath: path.join(__dirname, "src/"),
adapter: new JSONAdapter({
path: path.join(__dirname, "src/locales/"),
}),
languages: ["ko", "en", "es", "ja", "zh"],
};
@titusdecali
titusdecali / i18n.js
Created November 25, 2020 09:57
config for vue-i18n
import Vue from "vue";
import VueI18n from "vue-i18n";
Vue.use(VueI18n);
// On change of language, switch the /locals/_language_.json file
function loadLocaleMessages() {
const locales = require.context(
"./locales",
true,
@titusdecali
titusdecali / main.js
Last active December 28, 2021 22:46
Vue3 i18n main.js setup
import { createApp } from 'vue'
import App from './App.vue'
// i18n
import I18n from './i18n.js'
const i18n = createI18n({
locale:
localStorage.getItem('lang') ||
// Detect user's browser language
@titusdecali
titusdecali / scrollToTop.js
Last active June 17, 2021 22:15
VUE: Scroll to top after every route change
// In App.vue
watch: {
$route() {
window.scrollTo(0, 0)
}
},
@titusdecali
titusdecali / detectPlatform.js
Last active June 18, 2021 00:37
Detect Desktop or Mobile Device in Vue
async mounted() {
// Detect if user is on Desktop or Mobile platform, then save to store
this.$isMobile()
? this.$store.commit('setPlatform', 'mobile')
: this.$store.commit('setPlatform', 'desktop')
},
@titusdecali
titusdecali / utils.js
Last active June 18, 2021 00:57
Global Vue Utility Function Example
// import store from '../store' <-- To access your Vuex store
import Vue from 'vue' // <-- used for vue-toastification
class Utils {
// Copy a string to user's clipboard
copyToClipboard(text) {
let copyText = document.createElement('input')
document.body.appendChild(copyText)
copyText.value = text
copyText.select()
@titusdecali
titusdecali / Button.vue
Last active June 18, 2021 01:18
Vue Dynamic Button Component example
<template>
<button
:disabled="disabled"
:type="type"
class="btn"
:class="[
variant ? `btn-${variant}` : '',
disabled ? disabled : ''
]"
@click="!disabled ? $emit('clicked') : ''"
@titusdecali
titusdecali / parentToChild.js
Last active June 20, 2021 01:51
Vue: Access data in $parent from child
// In parent
data() {
return {
message: 'This is my message'
}
}
// In child template
<div>{{ $parent.message }}</div> // <-- results in 'This is my message'
@titusdecali
titusdecali / accessRouterData.vue
Created June 20, 2021 05:55
Vue: Access all vue-router routes and metadata
v-for="(route, idx) in $router.options.routes.filter(
(routeItem) => routeItem.name === $route.matched[0].name
)"