$(this) и $(this).get(0)?$(this).paused всегда будет undefined, а вовсе не true или false.if (this.paused) {
this.play();
} else {
this.pause();
}
// или
this[this.paused ? 'play' : 'pause']();
connect(mapStateToProps, null)(Authentication);
let intervalId = null;
$(window).on('scroll', function() {
const scr = $(this).scrollTop();
const elem = $('.count-wrapper').offset().top;
if (scr > elem - 400 && !intervalId) {
intervalId = setInterval(count, 10);
}
}).scroll();
function count() {
let countEnd = true;
$('.count span').each(function() {
const num = $(this).data('num');
const currNum = $(this).text();
if (currNum < num) {
$(this).text(+currNum + 1);
countEnd = false;
}
});
if (countEnd) {
clearInterval(intervalId);
}
}
на второй возникает ошибка, что я делаю не так?
как лучше реализовать, чтобы замена символа происходила в том же окне
<textarea v-model="input"></textarea>data: () => ({
input: '',
}),
watch: {
input(v) {
this.input = v.split('1').join('2');
},
},<textarea v-model="input" @input="onInput"></textarea>data: () => ({
input: '',
}),
methods: {
onInput() {
this.input = this.input.split('1').join('2');
},
},
Все делал по этой документации...
<section v-if="show" transition="fade"></section><transition name="fade">
<section v-if="show"></section>
</transition>transition(name="fade")
section(v-if="show")
{{#Status}}
<div>{{Title}}</div>
{{#Items}}
<div>{{Name}}: {{Count}}</div>
{{/Items}}
{{/Status}}
$elems.not(i => i % N).addClass('xxx');
// или
elems.forEach((n, i) => n.classList.toggle('xxx', !(i % N)));
// или
for (let i = 0; i < elems.length; i += N) {
elems[i].classList.add('xxx');
}
В таблице MySQL есть поле recdate типа DATE.
<td>{{ tran.recdater }} </td>v-for по нему:data: () => ({
columns: [
{ key: 'recdate', label: 'Date' },
{ key: 'refnum', label: 'Refnum' },
{ key: 'client', label: 'Client' },
{ key: 'details', label: 'Details' },
{ key: 'amount', label: 'Amount' },
{ key: 'cur', label: 'CUR' },
],
...
}),<thead>
<tr>
<th v-for="col in columns">{{ col.label }}</th>
</tr>
</thead>
<tbody>
<tr v-for="row in trans">
<th v-for="col in columns">{{ row[col.key] }}</th>
</tr>
</tbody>
$str = '< p > text </p>';
$count = 0;
$str = preg_replace_callback('/< ?\/?\w+ ?\>/', function() use(&$count) {
$count++;
return "#p$count";
}, $str);$str = '< p > text </p> <b> fdsgdfsg</b> <p>???</p> <div>hello, world!!< /div>';
$count = [];
$str = preg_replace_callback('/< ?\/?(\w+) ?\>/', function($matches) use(&$count) {
$key = $matches[1];
$count[$key] = isset($count[$key]) ? $count[$key] + 1 : 1;
return "#$key$count[$key]";
}, $str);
array2.forEach(n => {
const obj = array1.find(m => m.name === n.name);
if (obj) {
Object.assign(obj, n);
} else {
array1.push({ ...n });
}
});
$(document).on('click', '[data-slide-to]', function() {
$(this).closest('.carousel').carousel(+this.dataset.slideTo);
});
<div class="tab-headers">
<button data-id="1">69</button>
<button data-id="2">187</button>
<button data-id="3">666</button>
</div>
<div class="tab-contents">
<div data-id="1">hello, world!!</div>
<div data-id="2">fuck the world</div>
<div data-id="3">fuck everything</div>
</div>.tab-contents div {
display: none;
}
.tab-contents div.active {
display: block;
}
.tab-headers button.active {
background: red;
color: white;
}const headerSelector = '.tab-headers button';
const contentSelector = '.tab-contents div';
const activeClass = 'active';
// делегирование, назначаем обработчик клика один раз для всех кнопок;
// соответствие кнопок и блоков устанавливаем через равенство атрибутов
document.addEventListener('click', e => {
const header = e.target.closest(headerSelector);
if (header) {
const { id } = header.dataset;
const toggle = n => n.classList.toggle(activeClass, id === n.dataset.id);
document.querySelectorAll(headerSelector).forEach(toggle);
document.querySelectorAll(contentSelector).forEach(toggle);
}
});
// или, назначаем обработчик клика каждой кнопке индивидуально;
// соответствие кнопок и блоков устанавливаем через равенство индексов
const headers = document.querySelectorAll(headerSelector);
const contents = document.querySelectorAll(contentSelector);
headers.forEach(n => n.addEventListener('click', onClick));
function onClick() {
const index = Array.prototype.indexOf.call(headers, this);
const toggle = (n, i) => n.classList.toggle(activeClass, i === index);
headers.forEach(toggle);
contents.forEach(toggle);
}
const str = '1 2 3 4 5 6 7 8 9 0';
// регулярное выражение есть
str.replace(/([^ ]+ [^ ]+) /g, '$1;')
// регулярного выражения нет
str.split(' ').map((n, i) => i ? '; '[i & 1] + n : n).join('')
const fs = require('fs');
let ID = 0;
const clients = {};
new (require('ws').Server)({
port: 8081,
}).on('connection', ws => {
const id = ++ID;
clients[id] = ws;
ws.on('close', () => {
delete clients[id];
});
});
fs.watch('./', (eventType, filename) => {
if (/\.json$/.test(filename)) {
fs.readFile(filename, 'utf8', (err, data) => {
if (!err && data) {
const info = JSON.stringify({
filename,
data: JSON.parse(data),
});
Object.values(clients).forEach(n => n.send(info));
}
});
}
});<div id="app">
<div v-for="(data, name) in files">
<div>{{ name }}</div>
<div>{{ data }}</div>
</div>
</div>new Vue({
el: '#app',
data: {
socket: null,
files: {},
},
created() {
this.socket = new WebSocket('ws://localhost:8081');
this.socket.onmessage = e => {
const f = JSON.parse(e.data);
this.$set(this.files, f.filename, f.data);
};
},
});