после 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
), [])
<div id="app"></div>
function App() {
const [ dark, setDark ] = React.useState(null);
const updateDark = e => setDark(e.type === 'mouseover' ? e.currentTarget.id : null);
return (
<React.Fragment>
{[ 'left', 'right' ].map(n => (
<div
id={n}
key={n}
onMouseOver={updateDark}
onMouseLeave={updateDark}
className={dark && dark !== n ? 'dark' : ''}
></div>
))}
</React.Fragment>
);
}
ReactDOM.render(<App />, document.getElementById('app'));
if (novyna.lenght) {
в процессе экспериментов было установлено, что если написать в условии вообще какую-либо фигню, типа if(novyna.lenght=55), то новости выводятся как ни в чем не бывало
class News extends React.Component {
const News = ({ news }) =>
<div className="news">
{Array.isArray(news) && news.length
? news.map(n => (
<div key={n.id}>
<p className="news__author">{n.author}:</p>
<p className="news__text">{n.text}</p>
<hr/>
</div>
))
: <p>Нет</p>}
<strong>Всего новостей: {news.length}</strong>
</div>;