@23g/pacos-js 中文文档教程
Pacos JS
23G 项目的组件/帮助程序库。
Installation
通过 NPM 安装……
npm i pacos-js
……然后像这样导入
import {
UiInput,
UiSelect,
} from 'pacos-js';
import {
getDeep,
loadImage,
sleep,
} from 'pacos-js/helpers';
Components
Registration
// global
Vue.component('ui-input', UiInput);
// or local
new Vue {
el: '#app',
components: {
UiInput,
},
};
Helpers
sleep
只是一个更漂亮的函数,用于将超时与 async/await 结合使用。
const doStuff = async () => {
console.log('Do something now...');
await sleep(500);
console.log('...and when 500ms passes');
};
getDeep
当属性未定义时防止类型错误。
const response = {
name: {
first: 'Youri',
last: 'Hanssens',
},
};
getDeep(response, 'name.first');
// e.g. 'Youri';
getDeep(response, 'name.does.not.exist');
// e.g. false
loadImage
当给定的 src 被浏览器加载时返回一个承诺的简单函数。
const doStuffAfterImageLoaded = async () => {
const src = 'https://dummyimage.com/400x400';
await loadImage(src);
console.log(`${src} is loaded`);
};
Development
Use linters by running watch
npm run watch
Creating a test build
npm pack
Pacos JS
Component / helper library for 23G projects.
Installation
Install via NPM…
npm i pacos-js
…and import like
import {
UiInput,
UiSelect,
} from 'pacos-js';
import {
getDeep,
loadImage,
sleep,
} from 'pacos-js/helpers';
Components
Registration
// global
Vue.component('ui-input', UiInput);
// or local
new Vue {
el: '#app',
components: {
UiInput,
},
};
Helpers
sleep
Just a prettier function for using timeouts with async/await.
const doStuff = async () => {
console.log('Do something now...');
await sleep(500);
console.log('...and when 500ms passes');
};
getDeep
Prevents type errors when properties are undefined.
const response = {
name: {
first: 'Youri',
last: 'Hanssens',
},
};
getDeep(response, 'name.first');
// e.g. 'Youri';
getDeep(response, 'name.does.not.exist');
// e.g. false
loadImage
Simple function that returns a promise when the given src is loaded by the browser.
const doStuffAfterImageLoaded = async () => {
const src = 'https://dummyimage.com/400x400';
await loadImage(src);
console.log(`${src} is loaded`);
};
Development
Use linters by running watch
npm run watch
Creating a test build
npm pack