не получается обратиться к геттеру <...> показывает null, хотя если вызвать store.getters, то данные есть
<компонент v-if="$store.getters.profile" />
//Подключаю хранилище import store from './store'; store.dispatch('getUser'); new Vue({ el: '#app', router: router, components:{ 'head-app':headImplant, 'footer-app':footer, 'sidebar-app': sidebar } });
new Vue({
store,
...
class App extends Component {
state = {
users: []
}
componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(users => this.setState({ users }));
}
render() {
return(
<div className="App">
<table>
<tbody>
{this.state.users.map(n => (
<tr key={n.id}>
<td>{n.name}</td>
<td>{n.username}</td>
<td>{n.email}</td>
<td>{n.website}</td>
</tr>
))}
</tbody>
</table>
</div>
)
}
}
<select id="person"></select>
<select id="key"></select>
<span id="value"></span>
const data = [
{
"ФИО": "Иванов Сергей",
"Адрес": {
"Город": "Москва",
"Улица": "Пятницкая",
"Дом": "35",
},
},
{
"ФИО": "Сидоров Иван",
"Адрес": {
"Город": "Питер",
"Улица": "Ленина",
"Дом": "42",
},
},
];
const selects = [
Select('#person', data.map(n => n['ФИО'])),
Select('#key', Object.keys(data[0]['Адрес'])),
];
selects.forEach(n => n.addEventListener('change', onChange));
function Select(selector, options) {
const el = document.querySelector(selector);
el.append(...options.map(n => new Option(n)));
el.value = null;
return el;
}
function onChange() {
const [ person, key ] = selects.map(n => n.value);
if (person && key) {
const value = data.find(n => n['ФИО'] === person)['Адрес'][key];
document.querySelector('#value').textContent = value;
}
}
const getUnique = arr => Array
.from(arr.reduce((acc, n) => acc.set(n, acc.has(n)), new Map))
.reduce((acc, n) => (n[1] || acc.push(n[0]), acc), []);
const result = getUnique(arr);
const getByCount = (arr, checkCount) => Array
.from(arr.reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map))
.reduce((acc, n) => (checkCount(n[1]) && acc.push(n[0]), acc), []);
const result = getByCount(arr, count => !~-count);
v-if="accounts"
и v-if="transactions"
тем блокам, внутри которых рендерятся элементы на основе соответствующих свойств. Является ли нормальной практикой создание нового метода , включающего в себя эти три метода
buildButton(() => {
this.drawSomeButtons();
this.changeSomeVariables();
this.doSomethingElse();
});
x
- свойство экземпляра, другой - статический геттер:class Base {
constructor() {
this.x = 3;
}
static get x() {
return 1.5;
}
}
function Base() {
this.x = 3;
}
Base.x = 1.5;
// или
function Base() {}
Base.prototype.x = 3;
Base.x = 1.5;
class Base {
x = 3;
static x = 1.5;
}
this.steppers[index]=this.steppers[index]+this.step_go
this.$set(this.steppers, index, this.steppers[index] + this.step_go)
$str = "философски нагруженная";
preg_match("/.{50}$str.{50}/u", $text, $match);
const getValue = (obj, index = 0) =>
Object.values(obj)[index];
function getValue(obj, index = 0) {
for (const k in obj) {
if (obj.hasOwnProperty(k) && !index--) {
return obj[k];
}
}
}
$('.list_add_room').on('click', '.butt_edit', function() {
const $el = $(this).closest('.item_contain_list').find('p');
$('.list_add_room [contenteditable="true"]').not($el).removeAttr('contenteditable');
$el.attr('contenteditable', (i, val) => val !== 'true').focus();
});
$('.list_add_room').on('click', '.butt_edit', function() {
$(this).closest('.item_contain_list').find('p').attr('contenteditable', 'true').focus();
}).on('blur', '[contenteditable="true"]', function() {
$(this).removeAttr('contenteditable');
});
$(function() { })
, или воспользуйтесь делегированием:$(document).on('change', 'input[type="radio"]', function() {
$('.color').text($(this).val());
});
я открыл доселе неизвестный it-сообществу баг...
... или где-то далеко по мне плачет один учебник по js?
setInterval(this.tick, interval);
наsetInterval(this.tick.bind(this), interval);
setInterval(() => this.tick(), interval);
document.querySelectorAll('.u-combolist label').forEach(n => {
if (n.textContent.toLowerCase().indexOf(genre) != -1) {
n.previousElementSibling.checked = true;
}
});
$('.u-combolist label')
.filter((i, n) => $(n).text().toLowerCase().includes(genre))
.prev()
.prop('checked', true);
const $el = $('.field');
const el = document.querySelector('.field');
$el.append(document.createTextNode(str));
// или
$el.append(new Text(str));
// или
$el.append(str.replace(/</g, '<'));
// или
el.append(str);
$el.append($(str).text());
// или
const div = document.createElement('div');
div.innerHTML = str;
el.insertAdjacentText('beforeend', div.innerText);
// или
el.append(document.createRange().createContextualFragment(str).textContent);
// или
el.append(new DOMParser().parseFromString(str, 'text/html').body.textContent);