как правильно сделать из этого директиву?
Note: This method is obsolete and should not be used. In particular, to interact with the clipboard, consider using the Clipboard API instead.
const clipboardDirective = (() => {
const values = new Map();
const onClick = e => navigator.clipboard.writeText(values.get(e.currentTarget));
return {
bind(el, binding) {
el.addEventListener('click', onClick);
values.set(el, binding.value);
},
update(el, binding) {
values.set(el, binding.value);
},
unbind(el) {
el.removeEventListener('click', onClick);
values.delete(el);
},
};
})();
Vue.directive('clipboard', clipboardDirective);
data: () => ({
scroll: 0,
...
}),
created() {
window.addEventListener('scroll', () => this.scroll = window.scrollY);
},
computed: {
scrollClasses() {
return что-то, в зависимости от значения this.scroll;
},
...
},
<div :class="scrollClasses"></div>
array.reduce((acc, el) => {
el.forEach((n, i) => {
acc[i] = acc[i] || [];
n.forEach((m, j) => (acc[i][j] = acc[i][j] || []).push(...[].concat(m)));
});
return acc;
}, [])
const result = ind.reduce((acc, col) => {
arr.forEach((n, i) => {
acc[i].push(i ? n.filter((m, j) => arr[0][j] === col) : col);
});
return acc;
}, arr.map(() => []));
const indObj = Object.fromEntries(ind.map((n, i) => [ n, i ]));
const result = arr.reduce((acc, n, i) => (
i && n.forEach((m, j) => acc[i][indObj[arr[0][j]]].push(m)),
acc
), arr.map((_, i) => ind.map(n => i ? [] : n)));
const min = 666;
const inputSelector = 'input';
const buttonSelector = 'button';
const input = document.querySelector(inputSelector);
const button = document.querySelector(buttonSelector);
input.addEventListener('input', e => button.disabled = e.target.value < min);
input.dispatchEvent(new Event('input'));
// или
const $input = $(inputSelector);
const $button = $(buttonSelector);
$input.on('input', () => $button.prop('disabled', $input.val() < min)).trigger('input');
const Modal = (props) => {
const onClick = e => {
if (e.target.classList.contains('close') || !e.target.closest('.modal-content')) {
props.close();
}
}
return (
<div className="modal" onClick={onClick}>
<div className="modal-content">
<span className="close">×</span>
{props.children}
</div>
</div>
);
};
const App = () => {
const [ opened, setOpened ] = React.useState(false);
const open = () => setOpened(true);
const close = () => setOpened(false);
return (
<div>
<h2>Modal Example</h2>
<button onClick={open}>Open Modal</button>
{opened && <Modal close={close}>hello, world!!</Modal>}
</div>
);
}
slick-slide
у предков целевого элемента, номер слайда можно определить через атрибут data-slick-index
(или можете назначать слайдам какие-то свои классы/атрибуты для выяснения, где был произведён клик).const className = 'qq-upload-file';
.const elements = document.querySelectorAll(`.${className}`);
// или
const elements = document.getElementsByClassName(className);
const getText = el => el.textContent;
// или
const getText = el => el.innerText;
// или (т.к., вложенных элементов нет)
const getText = el => el.innerHTML;
const texts = Array.from(elements, getText);
// или
const texts = Array.prototype.map.call(elements, getText);
// или
const texts = [];
for (const n of elements) {
texts.push(getText(n));
}
// или
const texts = [];
for (let i = 0; i < elements.length; i++) {
texts[i] = getText(elements[i]);
}
const uniqueCount = new Set(texts).size;
// или
const { size: uniqueCount } = new Map(texts.map(n => [ n, n ]));
// или
const [ uniqueCount ] = texts.reduce((acc, n) => {
acc[0] += !(acc[1][n] = acc[1].hasOwnProperty(n));
return acc;
}, [ 0, {} ]);
// или
const uniqueCount = texts.filter((n, i, a) => i === a.indexOf(n)).length;
const inputs = document.querySelectorAll('form input');
// или
const inputs = document.forms[0].elements;
// или
const inputs = document.querySelector('form').getElementsByTagName('input');
const getName = el => el.name;
// или
const getName = el => el.getAttribute('name');
// или
const getName = el => el.attributes.name.value;
const names = Array.from(inputs, getName);
// или
const names = Array.prototype.map.call(inputs, getName);
// или
const names = [];
for (const n of inputs) {
names.push(getName(n));
}
// или
const names = [];
for (let i = 0; i < inputs.length; i++) {
names[i] = getName(inputs[i]);
}
activeProjects.map((project, i) => { <div key={i} className="focus-projects">
render() {
const activeProjects = this.props.projects.filter(n => n.ProjectStatus === 'ACTIVE');
...
const result = Object
.entries(arr.reduce((acc, n, i) => ((acc[n] = acc[n] || []).push(i), acc), {}))
.map(([ label, indexes ]) => indexes.length > 1 ? { label, indexes } : label);
const result = Object.values(arr.reduce((acc, n) => (
(acc[n.ID] = acc[n.ID] || { ID: n.ID })[n.FIELD] = n.VALUE,
acc
), {}));