watch: {
measureSystem: {
immediate: true,
handler() {
// сюда переносите код из mounted - axios.get(...)
},
},
},
computed: {
measureSystem() {
return this.toggle === 1 ? 'metric' : 'Imperial';
},
},
$(window).scroll(function onScroll() {
if ($(this).scrollTop() > 777) {
$('.div_clone').clone().appendTo('.container2');
$(this).off('scroll', onScroll);
}
});
rectPath = `M0 0 v${vert} h${horz} v${-vert} h${-horz}`
cellPath = ([ x, y ]) => `M${offset(x)} ${offset(y)} h${side} v${side} h${-side} v${-side}`
const isAllUnique = (...args) => new Set(args).size === args.length;
console.log(isAllUnique(69, 187, 666)); // true
console.log(isAllUnique(2, 2, 3, 4)); // false
console.log(isAllUnique(...'ABCDA')) // false
Допустимо ли использовать defs внутри symbol в SVG-элементе?
А тег style?
Где можно почитать о таких нюансах?
<input @change="doSomethingWithValue" />
methods: {
doSomethingWithValue(e) {
const value = e.target.value;
...
<input @change="doSomethingWithValue($event, 'hello, world!!')" />
$newData = array_map(function($item) {
return array_map(function($val) {
return [ 'text' => $val ];
}, array_values($item));
}, $data);
Проблема в том, что рисуется только последний график. Почему?
main.innerHTML += str;
main.insertAdjacentHTML('beforeend', str);
const canvas = document.createElement('canvas');
main.appendChild(canvas);
$('.nav').on('click', '[href="#id-3"]', function() {
$('.slick').slick('slickGoTo', 3);
});
const elems = [...document.querySelectorAll('.class1')];
const index = elems.findIndex(n => n.classList.contains('class2'));
const elems = document.querySelectorAll('.class1');
let index = elems.length;
while (--index >= 0 && !elems[index].matches('.class2')) ;
const index = Array.prototype.indexOf.call(
document.querySelectorAll('.class1'),
document.querySelector('.class2')
);
<div class="country">
<input class="country-code">
<img class="country-flag">
</div>
function updateFlag(el) {
const country = countries.find(n => !el.value.indexOf(n.code));
el.closest('.country').querySelector('.country-flag').src = country ? country.flag : '';
}
document.addEventListener('input', function(e) {
if (e.target.classList.contains('country-code')) {
updateFlag(e.target);
}
});
document.querySelectorAll('.country-code').forEach(updateFlag);
const countries = [
{ code: ..., flag: ... },
{ code: ..., flag: ... },
...
];
const country = countries.find(n => !inputCode.value.indexOf(n.code));
inputFlag.src = country ? country.flag : '';
<input type="number" min="0" max="100">
<table>
<tbody></tbody>
</table>
const input = document.querySelector('input');
const table = document.querySelector('table');
input.addEventListener('input', ({ target: t }) => {
const count = t.value = Math.max(0, t.value | 0);
const [ tbody ] = table.tBodies;
const { rows } = tbody;
for (; rows.length > count; tbody.deleteRow(-1)) ;
while (rows.length < count) {
const row = tbody.insertRow();
row.insertCell().textContent = '#' + rows.length;
row.insertCell().textContent = Math.random() * 1e3 | 0;
}
});
// или
input.oninput = function() {
const count = this.value = Math.max(0, +this.value || 0);
const tbody = table.querySelector('tbody');
const rows = tbody.children;
Array.prototype.slice.call(rows, Math.min(rows.length, count)).forEach(n => n.remove());
tbody.insertAdjacentHTML('beforeend', Array
.from({ length: Math.max(0, count - rows.length) }, (n, i) => `
<tr>
<td>#${rows.length + i + 1}</td>
<td>${Math.floor(Math.random() * 1000)}</td>
</tr>`)
.join('')
);
};
const classes = {
0: 'first',
[props.data.length - 1]: 'last',
};
className={classes[i]}
.