Skip to content

Instantly share code, notes, and snippets.

import { ref } from 'vue';
const useCounterUp = (initialVaue = 0) => {
const counter = ref(initialVaue);
const increment = () => counter.value += 1;
return { counter, increment };
};
const useCounterDown = (initialVaue = 0) => {
const counter = ref(initialVaue);
// definition
function $(s) { return new lib(s); }
function lib(s) { this.$els = document.querySelectorAll(s); }
lib.prototype.css = function(prop, val) {
this.$els.forEach($el => ($el.style[prop] = val));
// this is what makes it chainable
return this;
};
@darkylmnx
darkylmnx / vue.config.js
Created March 25, 2019 15:20
Load SCSS variables globally with Webpack in Vue or others
// In the vue.config.file
// I load globally in all my components 2 files
// that DO NOT contain CSS but just variables and functions
// If you add CSS in those files they would be duplicated in each component
module.exports = {
css: {
loaderOptions: {
sass: {
data: `
@import "@/assets/scss/variables.scss";
@darkylmnx
darkylmnx / home-global.php
Last active August 23, 2018 14:01
Expose Auth User Object to a Vue component in a Multi-App-Page
<?php require 'header.php' ?>
<?php if (isLogged()) : ?>
<script>
// this is one way, the global var way
// the function getAuthUser() returns an Object of the user
// oui json encode it which will give something like : { name: "", ... }
// and this when rendered here is a string, but in a browser it's a js object so no need for quotes or it will be a string in JS too
window.user = <?= json_encode(getAuthUser()) ?>;
</script>
@darkylmnx
darkylmnx / ASubLayout.vue
Last active July 30, 2018 22:11
Sub Layouts with Vue
<template>
<!-- this layout will not have any header or general things to all layouts -->
<div>
<h2> i'm a sub layout </h2>
<slot />
</div>
</template>
@darkylmnx
darkylmnx / app.js
Last active March 20, 2019 09:34
How do exports and imports work in JS bundlers ? (parcel etc...)
// this is app.js, your entry point in your HTML
import { data } from './data.js'
// we use brackets because we only want to export the "data" key exported
// though it will only contain "data" here, everything will be evaluated and executed in data.js
import './scripts'
// here, everything in scripts.js will be evaluated and executed BUT,
// no variables, constants or functions from scripts.js are accessible from here
// "sum" is not accessible, because "sum" was not exported from scripts.js