inputChange = e => {
const index = +e.target.dataset.index;
this.setState({
workers: this.state.workers.map((n, i) => i === index
? { ...n, checked: e.target.checked }
: n
),
});
}
<input
type="checkbox"
data-index={index}
onChange={this.inputChange}
checked={item.checked}
/>
const sum = this.state.workers.reduce((acc, n) => acc + (n.checked ? n.salary : 0), 0);
submitText = (e) => {
this.setState({
text: e.target.value,
});
}
function (response) {
на (response) => {
.axios(...).then(function(response) {
this.info = response.data;
}.bind(this));
const that = this;
axios(...).then(function(response) {
that.info = response.data;
});
methods: {
processResponse({ data }) {
this.info = data;
},
},
mounted() {
axios(...).then(this.processResponse);
},
async mounted() {
try {
this.info = (await axios(...)).data;
} catch (e) {}
},
const options = [
[ 'hello, world!!', 'fuck the world', 'fuck everything' ],
500,
(elem => item => elem.textContent = item)
(document.querySelector('.slide-words')),
];
function interval(arr, delay, callback) {
let i = -1;
return arr.length
? setInterval(() => callback(arr[i = -~i % arr.length]), delay)
: null;
}
const intervalId = interval(...options);
// надо остановить, делаем так: clearInterval(intervalId);
function interval(arr, delay, callback) {
let timeoutId = null;
arr.length && (function next(i) {
timeoutId = setTimeout(() => {
callback(arr[i]);
next((i + 1) % arr.length);
}, delay);
})(0);
return () => clearTimeout(timeoutId);
}
const stop = interval.apply(null, options);
// надо остановить, делаем так: stop();
parseInt('')
будет NaN
.parseInt($(this).val())
на parseInt($(this).val()) || 0
. <span>hello, world!!... fuck the world... fuck everything</span>
body {
margin: 0;
background: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
span {
color: red;
font-size: 24px;
font-family: monospace;
}
.xxx {
display: inline-block;
min-width: 10px;
transition: all 0.2s;
transform: scale(1);
}
.hidden {
opacity: 0;
transform: scale(30);
}
function show(el) {
el.innerHTML = Array
.from(el.innerText, n => `<span class="xxx hidden">${n}</span>`)
.join('');
el.querySelectorAll('span').forEach((n, i) => {
setTimeout(() => n.classList.remove('hidden'), 100 * i);
});
}
show(document.querySelector('span'));
const getValue = el => el.textContent.match(/"(.*?)"/)[1];
// или
const getValue = ({ innerText: t }) =>
JSON.parse(t.slice(t.indexOf('['), -~t.indexOf(']'))).shift();
document.querySelectorAll('li button').forEach(function(n) {
n.addEventListener('click', this);
}, e => console.log(getValue(e.target)));
document.querySelector('ul').addEventListener('click', e => {
if (e.target.tagName === 'BUTTON') {
console.log(getValue(e.target));
}
});
data: () => ({
items: Array(10).fill(null),
...
<ul>
<li v-for="(n, i) in items" :style="index < i || { color: n }">
{{ i }}
</li>
</ul>
methods: {
next(color) {
const { index, items } = this;
this.index = index === items.length - 1 ? 0 : index + 1;
items.splice(this.index, 1, color);
},
...
data: () => ({
colors: [ 'red', 'lime', 'blue', 'orange', 'magenta', 'aqua', 'yellow' ],
...
<button v-for="c in colors" @click="next(c)">{{ c }}</button>
headerObj.offsetTop
const frame = document.getElementsByTagName('iframe')[0];