Skip to content

Instantly share code, notes, and snippets.

Avatar

Nosa Obaseki c0depanda

View GitHub Profile
@c0depanda
c0depanda / imageUpload.vue
Last active Feb 7, 2017
Uploading Data to an api endpoint using Vue Resource and FormData Web Api
View imageUpload.vue
<template>
<div>
<input type="file" @change="avatarChange" class="uploadIcon">
</div>
</template>
<script>
export default {
@c0depanda
c0depanda / ref.vue
Created Jun 19, 2017
Method for creating a unique reference number
View ref.vue
<template>
<div>
<p>Reference Number: {{referenceNumber}}
</div>
</template>
<script>
export default {
data: function () {
return {
View longpress-start.js
// Create timeout ( run function after 1s )
let start = (e) => {
// Make sure the event trigger isn't a click event
if (e.type === 'click' && e.button !== 0) {
return;
}
// Make sure we don't currently have a setTimeout running
// before starting another
if (pressTimer === null) {
View longpress-cancel.js
let cancel = (e) => {
// Check if timer has a value or not
if (pressTimer !== null) {
clearTimeout(pressTimer)
pressTimer = null
}
}
View longpress-final.js
// Define variable
let pressTimer = null;
// Create timeout ( run function after 1s )
let start = (e) => {
if (e.type === 'click' && e.button !== 0) {
return;
}
View longpress-directive.js
Vue.directive('longpress', {
bind: function (el, binding, vNode) {
// Make sure expression provided is a function
if (typeof binding.value !== 'function') {
// Fetch name of component
const compName = vNode.context.name
// pass warning to console
let warn = `[longpress:] provided expression '${binding.expression}' is not a function, but has to be`
if (compName) { warn += `Found in component '${compName}' ` }
View store.js
// import Vue
import Vue from 'vue';
// import Vuex
import Vuex from 'vuex';
// Install the Vuex plugin on vue
Vue.use(Vuex);
// create a Vuex store instance
export const store = new Vuex.Store({
View example1.vue
<template>
<main>
<h1>Cart Content</h1>
<p>{{cartValue}}</p>
</main>
</template>
<script>
// Import Vuex Store into Component
import store from 'store.js';
View example2.vue
<template>
<main>
<h1>Cart Content</h1>
<p>{{cartValue}}</p>
</main>
</template>
<script>
export default {
computed: {