Skip to content

Instantly share code, notes, and snippets.

View afontcu's full-sized avatar
🚴‍♂️
¯\_(ツ)_/¯ ‏‏‎

Adrià Fontcuberta afontcu

🚴‍♂️
¯\_(ツ)_/¯ ‏‏‎
View GitHub Profile
function assert (actual) {
return {
equals (expected) {
if (actual !== expected) {
throw new Error(`${actual} is not equal to ${expected}`)
}
console.log(`${actual} equals ${expected}`)
}
}
}
function apiRequest({
endpoint,
method = 'GET',
getParams = {},
headers = ['Content-Type: text-plain'],
callback = () => {},
timeout = 0,
authRequest = true,
} = {}) {
//...
apiRequest({ // notice the curly braces! we are passing an object now
endpoint: 'products',
method: 'GET',
getParams: { category: 3 },
headers: ["Content-Type: text/plain"],
callback: function(response) {},
timeout: 0,
authRequest: true
})
<template>
<div>
<h1>Election day!</h1>
<button @click="voteForRed">Vote for 🔴</button>
<button @click="voteForBlue">Vote for 🔵</button>
<h2>Results</h2>
<results/>
<total-votes/>
</div>
<script>
import Vue from 'vue'
const state = new Vue({
data () {
return { red: 0, blue: 0 }
},
methods: {
voteForRed () { this.red++ },
voteForBlue () { this.blue++ },
<template>
<div>
<h1>Election day!</h1>
<button @click="voteForRed">Vote for 🔴</button>
<button @click="voteForBlue">Vote for 🔵</button>
<h2>Results</h2>
<results/>
<total-votes/>
</div>
<template>
<div>
<h1>Election day!</h1>
<button @click="voteForRed">Vote for 🔴</button>
<button @click="voteForBlue">Vote for 🔵</button>
<h2>Results</h2>
<results :red="red" :blue="blue" />
<total-votes :total="red + blue" />
</div>
<template>
<div>
<component :is="componentInstance" />
</div>
</template>
<script>
export default {
props: {
isCompany: { type: Boolean, default: false },
<template>
<div>
<component :is="componentName" />
</div>
</template>
<script>
import UserInfo from './components/UserInfo'
import CompanyInfo from './components/CompanyInfo'
@afontcu
afontcu / SimpleDemo.vue
Last active January 4, 2019 14:44
Simple import
<template>
<div>
<company-info v-if="isCompany" />
<user-info v-else />
...
</div>
</template>
<script>
import UserInfo from './components/UserInfo'