data: () => ({
options: [
{ value: 69, text: 'hello, world!!' },
{ value: 187, text: 'fuck the world' },
{ value: 666, text: 'fuck everything' },
],
value: null,
}),
computed: {
selectedText() {
return (this.options.find(n => n.value === this.value) || {}).text || '';
},
},
<select v-model="value">
<option v-for="n in options" :value="n.value">{{ n.text }}</option>
</select>
<div>
Текст выбранной опции: <span>{{ selectedText }}</span>
</div>
в итоге выводится не разница, а просто текущее значение показателя
watch: {
totalBuyQuantity(newVal, oldVal) {
this.buyDiff = newVal - oldVal;
},
},
const length = Math.max(...players.map(n => n.holes.length));
// или
const length = players.reduce((max, { holes: { length: n } }) => max > n ? max : n, 0);
for (const { holes } of players) {
holes.push(...Array.from(
{ length: length - holes.length },
() => ({ score: '-' })
));
}
const newPlayers = players.map(n => ({
...n,
holes: Array.from({ length }, (_, i) => n.holes[i] || { score: '-' }),
}));
$('.select-list').change(function() {
const selected = $(':checked', this)
.parent()
.get()
.map(n => $(n).text().trim())
.join(', ');
$('.selected-name--filter').text(selected || 'Любой');
}).change();
const select = document.querySelector('.select-list');
select.addEventListener('change', function() {
const selected = Array
.from(this.querySelectorAll(':checked'), n => n.parentNode.textContent.trim())
.join(', ');
document.querySelector('.selected-name--filter').textContent = selected || 'Любой';
});
select.dispatchEvent(new Event('change'));
this.setState(({ clientData }) => ({
clientData: {
...clientData,
active: !clientData.active,
},
}));
$('a').attr('title', function() {
return $(this).text();
});
document.querySelectorAll('a').forEach(n => n.title = n.innerText);
for (const n of document.getElementsByTagName('a')) {
n.setAttribute('title', n.textContent);
}
$('select').change(function() {
$('button').prop('disabled', $(this).val() === '0');
});
document.querySelector('select').addEventListener('change', function() {
document.querySelector('button').disabled = this.value === '0';
});
data: () => ({
opened: null,
blocks: [
{ id: 1, content: 'Я первый' },
{ id: 2, content: 'А я второй' },
{ id: 3, content: 'Третьим буду' },
],
}),
<a v-for="b in blocks" @click="opened = b">открыть {{ b.id }} блок</a>
<div v-if="opened" :class="`block-${opened.id}`">
<a @click="opened = null">Скрыть блок</a>
<div class="content">{{ opened.content }}</div>
</div>
function getTree(data) {
let root = data.find(n => n.id === 0);
root = { title: root.name.slice(1,-1), id: root.id };
data.filter(n => n.id !== 0).forEach(item => {
const node = item.name.slice(1, -1).split('/').reduce((parent, title) => {
if (!parent.children) {
Object.assign(parent, { children: [], isDirectory: true });
}
let child = parent.children.find(m => m.title === title);
if (!child) {
child = { title };
parent.children.push(child);
}
return child;
}, root);
Object.assign(node, { id: item.id, isDirectory: !!node.isDirectory });
});
return root;
}
filters: {
price: val => val.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1 ").replace('.', ','),
},
td {{ product.price | price }}
price: val => val.toLocaleString('ru', {
style: 'currency',
currency: 'RUB',
}),