Various functions associated with programming in Vue.
Last active
June 17, 2020 13:54
-
-
Save jbnv/df2092d552836e2b2452d6a377f4533b to your computer and use it in GitHub Desktop.
Various functions associated with programming in Vue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment