state = {
block1: false,
block2: false,
}
componentDidMount() {
setTimeout(() => this.setState({ block1: true }), 3000);
setTimeout(() => this.setState({ block2: true }), 6000);
}
render() {
const { block1, block2 } = this.state;
return (
...
{block1 && <div class="block-1">Блок 1</div>}
{block2 && <div class="block-2">Блок 2</div>}
...
);
}
<div id="app">
<todo-add @todo-new="addNewTodo"></todo-add>
<pre>{{ todoJson }}</pre>
</div>
Vue.component('todo-add', {
template: `
<div>
<input v-model="name" autofocus></input>
<button @click="add">Add New Todo</button>
</div>`,
data: () => ({
name: '',
}),
methods: {
add() {
const name = this.name.trim();
if (name) {
this.$emit('todo-new', name);
this.name = '';
}
},
},
});
new Vue({
el: '#app',
data: {
todoArr: [
{ id: 1, name: 'hello, world!!' },
],
},
methods: {
addNewTodo(name) {
this.todoArr.push({
id: 1 + Math.max(0, ...this.todoArr.map(n => n.id)),
name,
});
},
},
computed: {
todoJson() {
return JSON.stringify(this.todoArr, null, 2);
},
},
});
$('[data-index]').click(function() {
$('#main__display').html(`<img src="${collect[this.dataset.index]}">`);
});
document.querySelectorAll('[data-index]').forEach(function(n) {
n.addEventListener('click', this);
}, function(e) {
this.innerHTML = `<img src="${collect[e.currentTarget.dataset.index]}">`;
}.bind(document.querySelector('#main__display')));
const THICKNESS = {
thinLine: 1,
get midLine() {
return this.thinLine * 2;
},
get boldLine() {
return this.thinLine * 4;
},
};
после 21 итерации выдает неправильное значение даты
const startDate = new Date(2019, 7, 11);
const currentDate = new Date(startDate);
for (let i = 0; i <= 30; i++) {
currentDate.setDate(currentDate.getDate() + 1);
console.log(currentDate);
}
const startDate = new Date(2019, 7, 11);
for (let i = 0; i <= 30; i++) {
const currentDate = new Date(startDate);
currentDate.setDate(startDate.getDate() + i);
console.log(currentDate);
}
Vue.set(this.response.order.ordersItemsInfo[id], 'ordersItemsPropertiesInfo', [])
data: () => ({
items: [ 'active1', 'active2', 'active3' ],
active: false,
}),
<button @click="active = !active"></button>
...
<div v-for="n in items" :class="{ [n]: active }"></div>
function createList(data) {
const list = document.createElement('ul');
const stack = [];
let level = +data[0].match(/\d+/);
let ul = list;
for (const n of data) {
const currLevel = +n.match(/\d+/);
if (currLevel > level) {
stack.push([ ul, level ]);
[ ul, level ] = [ document.createElement('ul'), currLevel ];
stack[stack.length - 1][0].lastElementChild.append(ul);
} else {
for (; currLevel !== level; [ ul, level ] = stack.pop()) ;
}
ul.insertAdjacentHTML('beforeend', `<li>${n}</li>`);
}
return list;
}
await setTimeout
await new Promise(r => setTimeout(r, 1000))
.catch((e)=>{this.handleUsersListErrors(e)})
data: () => ({
status: 'unknown',
val: 'empty',
}),
methods: {
getVal() {
this.status = 'awaiting request answer';
return new Promise((...r) => {
setTimeout(() => {
const max = 10000;
this.val = Math.random() * max | 0;
r[+(this.val < max * 0.9)]();
}, 1000);
}).catch(this.handleError);
},
handleError() {
this.status = 'ERROR, awaiting new request';
return new Promise(r => setTimeout(r, 2000)).then(this.getVal);
},
},
async created() {
await this.getVal();
this.status = 'OK';
},
<div>status: {{ status }}</div>
<div>value: {{ val }}</div>
изучаю метод фильтр
greater than or equal to 8.0
rating > 8
combination of filter and map
watchList.filter(n => n.imdbRating >= 8).map(n => ({ title: n.Title, rating: n.imdbRating }))
// или
watchList.reduce((acc, { Title: title, imdbRating: rating }) => (
rating < 8 || acc.push({ title, rating }),
acc
), [])