data: () => ({
questions: [
{
text: '2 x 2?',
answers: [ '5', '3', '69', '187' ],
},
{
text: '...',
answers: [ '...', '...', ... ],
},
...
],
}) ,
props: [ 'text', 'answers', 'value' ],
<div>{{ text }}</div>
<div v-for="n in answers">
<label>
<input
type="radio"
:checked="n === value"
@change="$emit('input', n)"
>
{{ n }}
</label>
</div>
props: [ 'questions' ],
data: () => ({
index: 0,
answers: [],
}),
<div v-if="index < questions.length">
вопрос
</div>
<div v-else>
результаты
</div>
<question
v-bind="questions[index]"
v-model="answers[index]"
/>
:disabled="!answers[index]"
; б) скрывать - v-show="answers[index]"
):<button @click="index++">дальше</button>
<div v-for="(n, i) in questions">
{{ n.text }} - {{ answers[i] }}
</div>
const filterObject = (obj, values) =>
Object.entries(obj).reduce((acc, [ k, v ]) => (
values.indexOf(v) !== -1 && (acc[k] = v),
acc
), {});
const result = filterObject(a, b);
const filterObject = (obj, filter) =>
Object.fromEntries(Object.entries(obj).filter(n => filter(...n)));
const result = filterObject(a, (k, v) => b.includes(v));
return this.$store.authInfo
this.$store.state.authInfo
? Объект FileReader позволяет веб-приложениям асинхронно читать содержимое файлов
onFileChange({ target: { files: [ file ] } }) {
if (file) {
const reader = new FileReader();
reader.addEventListener('load', e => {
this.fileinput = e.target.result;
console.log(this.fileinput);
});
reader.readAsText(file);
}
},
const flat = arr =>
(arr || []).reduce((acc, { children, ...n }) => {
if (n.isExpanded || !children) {
acc.push(n, ...flat(children));
} else {
acc.push({ ...n, children });
}
return acc;
}, []);
isExpanded: false
у кого-то из предков уровнем выше родительского, тоconst flat = arr =>
(arr || []).reduce((acc, { children, ...n }) => {
const flatChildren = flat(children);
if (n.isExpanded || !children) {
acc.push(n, ...flatChildren);
} else {
acc.push({ ...n, children: flatChildren });
}
return acc;
}, []);
:class="form.FirstName !== null ? form.FirstName ? 'input-successes' : 'input-error' : ''"
:class="{ 'input-successes': form.FirstName, 'input-error': form.FirstName === false }"
:class="form.FirstName !== null && [ 'input-error', 'input-successes' ][+form.FirstName]"
:class="({ true: 'input-successes', false: 'input-error' })[form.FirstName]"
state = {
likes: localStorage.getItem('likes') | 0,
}
plus = () => {
this.setState(({ likes }) => ({
likes: likes + 1,
}), () => localStorage.setItem('likes', this.state.likes));
}
если в ней нет tr столбцов
$('table').show().not(':has(tbody tr)').hide();
for (const n of document.getElementsByTagName('table')) {
n.hidden = !n.querySelector('tbody tr');
}
.hidden {
display: none;
}
document.querySelectorAll('table').forEach(function(n) {
n.classList.toggle('hidden', this(n.tBodies));
}, tBodies => Array.prototype.every.call(tBodies, n => !n.rows.length));
infinite: false
в настройках слайдера.$slick.on('beforeChange', function(e, slick, currentSlide, nextSlide) {
$(this).find('.slick-next').prop('disabled', nextSlide === slick.slideCount - 1);
});
а как ей стиль менять?
slick-disabled
, можете с его помощью переопределять их внешний вид.const attacks = [
{ minChance: 7, damage: 40, name: 'critical' },
{ minChance: 5, damage: 20, name: 'big' },
{ minChance: 0, damage: 10, name: 'weak' },
];
const messages = {
start: (player, enemy) => `Welcome! Yor health is - ${player}%, your enemy health - ${enemy}%`,
end: (player, enemy) => `You ${enemy <= 0 ? 'win' : 'lost'}! Your hp level - ${player}, opponents hp level - ${enemy}`,
chance: (player, enemy) => `your chance - ${player}, your opponent chance - ${enemy}`,
turn: (player, enemy, hit, isEnemy) =>
`${isEnemy ? 'Enemy' : 'Your'} turn...
${isEnemy ? 'Enemy' : 'You'} did a ${hit} hit
${isEnemy ? 'Your' : 'Enemy'} hp - ${isEnemy ? player : enemy}`,
};
const simpleFight = () => {
const hp = [ 100, 100 ];
console.log(messages.start(...hp));
while (hp.every(n => n > 0)) {
const chances = hp.map(() => Math.random() * 11 | 0);
console.log(messages.chance(...chances));
if (chances[0] !== chances[1]) {
const chance = Math.max(...chances);
const attack = attacks.find(n => n.minChance < chance);
const isEnemyAttacks = chance === chances[1];
hp[+!isEnemyAttacks] -= attack.damage;
console.log(messages.turn(...hp, attack.name, isEnemyAttacks));
}
}
console.log(messages.end(...hp));
};
const sum = str.match(/\d+/g).reduce((acc, n) => acc + +n, 0);
// или
let sum = 0;
for (const n of str.split(/\D+/)) {
sum += Number(n);
}
preg_match_all('/\d+/', $str, $matches);
$sum = array_sum($matches[0]);
// или
$sum = 0;
foreach (preg_split('/\D+/', $str) as $n) {
$sum += intval($n);
}
id="mse2_ms|price_0"
|
засунуть в id.#
, а как значение атрибута, т.е. [id="mse2_ms|price_0"]
. после перезагрузки страницы получаю undefined
правильно ли я возвращаю копию значения с объекта store.singleMetricNamesMap
$store.state.singleMetricNamesMap[value.metricId]
. Если так по-вашему слишком длинно - сделайте в компоненте вычисляемое свойство, которое будет представлять singleMetricNamesMap. width: 100% !important;
, а родительский элемент canvas'а карты имеет нулевые размеры.new ymaps.Map("map", {