А можно как-то присваивать свой класс?
computed: {
activeLink() {
return this.links.find(n => n.url === this.$route.path);
},
},
:class="{ active: activeLink === link }"
created() {
const interval = setInterval(this.method, 5 * 60 * 1000);
this.$on('hook:beforeDestroy', () => clearInterval(interval));
},
return new this.constructor();
This expression is not constructable. Type 'Function' has no construct signatures
const { constructor } = Object.getPrototypeOf(this);
return new constructor();
<div class="phone">8 (123) 111-22-33</div>
<div class="phone">8 (456) 444-55-66</div>
<div class="phone">8 (789) 777-88-99</div>
document.querySelectorAll('.phone').forEach(n => {
const phone = n.innerHTML;
n.innerHTML = phone.slice(0, -4) + '... - <span>показать</span>';
n.querySelector('span').addEventListener('click', () => n.innerHTML = phone);
});
function filter(val) {
if (!(val instanceof Object)) {
return val;
}
const filtered = Object
.entries(val)
.map(n => [ n[0], filter(n[1]) ])
.filter(n => n[1]);
return filtered.length
? val instanceof Array
? filtered.map(n => n[1])
: Object.fromEntries(filtered)
: null;
}
const validator = (value, maxSize) =>
!(/[^а-яА-Яa-zA-Z0-9\s]/.test(value) || value.length > maxSize);
if (validator(value, maxSize)) {
setTitle(value);
}
const validator = (defaultValue, value, maxSize) =>
(/[^а-яА-Яa-zA-Z0-9\s]/.test(value) || value.length > maxSize)
? defaultValue
: value;
setTitle(prevValue => validator(prevValue, value, maxSize));
methods: {
createAlphaIndex(num) {
const base = 26;
let str = '';
do {
const mod = num % base;
num = num / base | 0;
str = (mod ? String.fromCharCode('A'.charCodeAt(0) + mod - 1) : (--num, 'Z')) + str;
} while(num);
return str;
},
},
<div v-for="i in 1000">{{ createAlphaIndex(i) }}</div>
const elements = document.querySelectorAll('.price');
const output = document.querySelector('.min-sum');
output.textContent = Math.min(...Array.from(
elements,
n => parseFloat(n.textContent)
));
// или
output.innerText = Array.prototype.reduce.call(
elements,
(min, n) => (
n = +n.innerText.match(/[\d.]+/),
n < min ? n : min
),
Infinity
);
const elem = document.querySelector('#elem').nextElementSibling;
if (elem) {
const num = 1 + [...elem.parentNode.children].indexOf(elem);
elem.innerText = num + '. ' + elem.innerText;
}
const elem = document.querySelector('#elem + *');
if (elem) {
let num = 1;
for (let n = elem; n = n.previousElementSibling; num++) ;
elem.textContent = `${num}. ${elem.textContent}`;
}
const elems = document.querySelector('ul').children;
const index = -~Array.prototype.findIndex.call(elems, n => n.id === 'elem');
if (index) {
elems[index]?.insertAdjacentText('afterbegin', ''.concat(-~index, '. '));
}
Как наиболее короче сделать...
generalDiv.innerHTML = newCats
.filter(n => n?.breeds.length)
.map(({ url, breeds: [ b ] }) => `
<div class="cat__item">
<div class="cat__img"><img src="${url}" alt="${b.name}"></div>
<div class="cat__name">${b.name}</div>
<div class="cat__temperament">${b.temperament}</div>
<div class="cat__live">${b.life_span}</div>
<div class="cat__origin">${b.origin}</div>
<div class="cat__description">${b.description}</div>
<div class="cat__wikipedia_url">${b.wikipedia_url}</div>
</div>
`)
.join('');
document.querySelector('form').addEventListener('input', function() {
const sum = Array.prototype.reduce.call(
this.querySelectorAll('input:checked'),
(acc, n) => acc + +n.value,
0
);
document.querySelector('#pSumma').innerText = `$${sum.toFixed(2)}`;
});
document.querySelectorAll('.g-project__words-moving').forEach(n => {
const html = n.querySelector('.words-moving__calm span').outerHTML.repeat(10);
n.querySelectorAll('.running-string-wrapp').forEach(m => m.innerHTML = html);
});
.words-moving__calm span
, вместо того, чтобы ограничиться только теми, которые лежат внутри текущего элемента .g-project__words-moving
. Для исправления можно перенести объявление place
в начало тела внешнего цикла, заменив при этом document
на boxes[i]
. .on('beforeChange', function(e, slick, currSlide, nextSlide) {
$('.tabs-content__item').hide().eq(nextSlide).fadeIn();
});