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.title
this.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 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] }
);