Skip to content

Instantly share code, notes, and snippets.

@jbnv
Last active June 17, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbnv/df2092d552836e2b2452d6a377f4533b to your computer and use it in GitHub Desktop.
Save jbnv/df2092d552836e2b2452d6a377f4533b to your computer and use it in GitHub Desktop.
Various functions associated with programming in Vue.
import Vue from '../app/mount.js';
import Clipboard from 'clipboard';
function clipboardSuccess() {
Vue.prototype.$message({
message: 'Copy successfully',
type: 'success',
duration: 1500,
});
}
function clipboardError() {
Vue.prototype.$message({
message: 'Copy failed',
type: 'error',
});
}
export default function handleClipboard(text, event) {
const clipboard = new Clipboard(event.target, {
text: () => text,
});
clipboard.on('success', () => {
clipboardSuccess();
clipboard.off('error');
clipboard.off('success');
clipboard.destroy();
});
clipboard.on('error', () => {
clipboardError();
clipboard.off('error');
clipboard.off('success');
clipboard.destroy();
});
clipboard.onClick(event);
}
/**
* Register our Vue components.
* Scans this directory and its subs for the Vue
* components and automatically registers them with their "basename".
*/
export default function(Vue) {
const files = require.context('./', true, /\.vue$/i);
files.keys().map(key => {
let component_name = key.split('/').pop().split('.')[0];
Vue.component(
component_name.replace(/\w[A-Z]/g, letter => letter[0] + '-' + letter[1]).toLowerCase(),
files(key).default
);
});
}
/**
* An object composed of the modules from this folder.
* Import this object, then add your local modules to it, then attach it to your store.
*/
import camelCase from 'camelcase';
// Ignore any files that start with "_".
const context = require.context('./modules', false, /[a-z-+]\.js$/);
// export default context.keys().reduce((accumulator, modulePath) => {
// const moduleName = camelCase(modulePath.replace(/^\.\/(.*)\.\w+$/, '$1'));
// const value = context(modulePath);
// accumulator[moduleName] = value.default;
// return accumulator;
// }, {
// });
export default context.keys().reduce((accumulator, modulePath) => {
const moduleName = camelCase(modulePath.replace(/^\.\/(.*)\.\w+$/,
'$1'));
const value = context(modulePath);
accumulator[moduleName] = value.default;
return accumulator;
}, {});

Various functions associated with programming in Vue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment