const result = [];
for (const k in obj) {
if (obj.hasOwnProperty(k)) {
result.push([ k, typeof obj[k] ]);
}
}typeof):const result = Object
.entries(obj)
.map(function(n) {
return [ n[0], this(n[1]) ];
}, x => x?.constructor.name ?? `${x}`);
props: {
multiple: Boolean,
...
},
computed: {
placeholder() {
return `Выберите ${this.multiple ? 'несколько значений' : 'одно значение'}`;
},
innerValue: {
get() {
const v = this.value;
return this.multiple || this.options.includes(v) ? v : '';
},
set(val) {
this.$emit('input', val);
},
},
},<select v-model="innerValue" :multiple="multiple">
<option disabled value="" v-text="placeholder"></option>
<option v-for="n in options">{{ n }}</option>
</select>
0 (например, для [ -1, 0, 0.1, 2 ] выдаёт 2 вместо 0.1). В первой части условия следует вместо предыдущего элемента массива смотреть индекс текущего - единственным неподходящим является нулевой.find. Для подмены undefined на null вообще не нужно никаких проверок делать - с этим справится nullish coalescing. Так что вот:const firstNonConsecutive = arr => arr.find((n, i, a) => i && a[i - 1] !== n - 1) ?? null;
N = 1000
M = 300
NM = N + M
newArr = sum((arr[i * NM:(i + 1) * NM - M] for i in range(ceil(len(arr) / NM))), [])
Error: [vuex] do not mutate vuex store state outside mutation handlers.
this.$store.commit('vehicles/addVehicle', { ...this.vehicle });
// или
addVehicle: (state, payload) => state.vehicles.push({ ...payload }),methods: {
createNewVehicle: () => ({
name: '',
description: '',
rent: '',
type: 'custom',
}),
...data() {
return {
vehicle: this.createNewVehicle(),
};
},this.$store.commit('vehicles/addVehicle', this.vehicle);
this.vehicle = this.createNewVehicle();
nextSlide = ({ target: { dataset: { step } } }) => {
this.setState(({ images: { length }, currentImageIndex: i }) => ({
currentImageIndex: Math.max(0, Math.min(length - this.props.slidesToShow, i + +step)),
}));
};<button onClick={this.nextSlide} data-step="-1">PREV</button>
<button onClick={this.nextSlide} data-step="+2">NEXT</button>
<span>{{ result.prices[result.indexOfSize] }}</span>items: [
{ size: '256GB', price: '99 999' },
{ size: '512GB', price: '105 999' },
],
index: 0,<label v-for="(n, i) in result.items">
<input type="radio" :value="i" v-model.number="result.index">
<span>{{ n.size }}</span>
</label>computed: {
selectedItem() {
return this.result.items[this.result.index];
},
...<span>{{ selectedItem.price }}</span>
@click="menuShow=!menuShow,goToBlock"@click="menuShow = !menuShow, goToBlock($event)". Ну а лучше бы конечно сделать новый метод (если goToBlock действительно нужен как отдельный метод, в противном случае достаточно унести в него переключение menuShow), как-то так:methods: {
goToBlock(selector) {
document.querySelector(selector).scrollIntoView({
behavior: 'smooth',
});
},
onMenuItemClick(e) {
this.menuShow = false;
this.goToBlock(e.target.getAttribute('href'));
},
},@click.prevent="onMenuItemClick"
arr.splice(0, arr.length, ...arr.map((n, i, a) => (a[i - 1] ?? 0) + (a[i + 1] ?? 0)));
const $links = $('.small a');
let currentIndex = null;
function setActiveImage(index) {
currentIndex = (index + $links.length) % $links.length;
$('.big img').attr('src', $links.eq(currentIndex).attr('href'));
$('.photo').text(`${currentIndex + 1} / ${$links.length}`);
}
$links.click(e => (e.preventDefault(), setActiveImage($links.index(e.currentTarget))));
$('#prev').click(() => setActiveImage(currentIndex - 1));
$('#next').click(() => setActiveImage(currentIndex + 1));
setActiveImage(0);
computed: {
needWatch() {
return Object.fromEntries(Object.entries(this.obj_lev_1).map(n => [ n[0], n[1].need_watch ]));
},
},watch: {
needWatch(newVal, oldVal) {
const [ k, v ] = Object.entries(newVal).find(n => n[1] !== oldVal[n[0]]);
alert(`${k}.need_watch changed from ${oldVal[k]} to ${v}`);
},
},
editTask (task, index) {v-model="editidTask.title"task.title = this.editTask.titlethis.tasks.map((task, index) => { if (index === this.editidTask.id) {
<list:tasks="task":key="task.title"v-show="isModal"null.task.date = this.editTask.date task.title = this.editTask.title
Object.assign.
const select = document.querySelector('select');
const reg = /^\d\d\. /;const mustBeHidden = el => !reg.test(el.text);
// или
const mustBeHidden = el => el.textContent.search(reg) !== 0;
// или
const mustBeHidden = el => el.innerText.match(reg) === null;
// или
const mustBeHidden = el => !~-el.innerHTML.split(reg).length;const toggle = el => el.hidden = mustBeHidden(el);
// или
const toggle = el => el.style.display = mustBeHidden(el) ? 'none' : '';
// или
const toggle = el => el.style.setProperty('display', mustBeHidden(el) ? 'none' : '');
// или
const toggle = el => el.style.cssText += `display: ${mustBeHidden(el) ? 'none' : 'block'}`;
// или
const toggle = el => el.setAttribute('style', mustBeHidden(el) ? 'display: none' : '');
// или (надо будет добавить в стили .hidden { display: none; })
const toggle = el => el.classList.toggle('hidden', mustBeHidden(el));Array.prototype.forEach.call(select.options, toggle);
// или
for (const n of select.children) {
toggle(n);
}
// или
for (let i = 0; i < select.length; i++) {
toggle(select[i]);
}
// или
(function next(i, n = select.item(i)) {
n && (toggle(n), next(-~i));
})(0);
// или
select.querySelectorAll('option').forEach(toggle);
const newData = data
.reduce((acc, { type, ...n }) => (
acc[acc.length - 1]?.[0] !== type && acc.push([ type, [] ]),
acc[acc.length - 1][1].push(n),
acc
), [])
.map(([ type, children ]) => children.length - 1
? { type: `Section${type}`, children }
: { type, ...children[0] }
);