onClick = ({ target: { dataset: { shift } } }) => {
this.setState(() => ({ shift }), this.filter);
}
response
следует передавать response.data
mutations: {
setTodos: (state, todos) => state.todos = todos,
},
actions: {
async getTodos({ commit }) {
const results = [];
for (let i = 1; i <= 10; i++) {
try {
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/todos/${i}`);
results.push(data);
} catch (e) {
console.log(e);
}
}
commit('setTodos', results);
},
},
<ul>
<li v-for="n in $store.state.todos" :key="n.id">
<div>#{{ n.id }}</div>
<div>{{ n.title }}</div>
</li>
</ul>
foreach ($arr as $itemName => $item) {
foreach ($item as $propName => $prop) {
foreach ($prop as $val) {
echo "$itemName : $val ; ($propName)<br>";
}
}
}
$("#idModalEditUser").modal('show').find('.modal-body').text($(this).text());
this.setState({ comments: comments.filter( (comment, i) => { return i !== index; }, () => localStorage.setItem("state", JSON.stringify(this.state)) ) });
watch: {
'$route.params.slug': {
immediate: true,
handler() {
// сюда переносите код из created
},
},
},
const arr = [ '***', '+++' ];
const obj = {
'!!!': [
{ id: 0, text: 'fjdklsfjklds' },
],
'+++': [
{ id: 3, a: '111', b: '!!!' },
{ id: 9, a: '222', b: '???' },
{ id: 27, a: '333', b: ':::' },
{ id: 81, a: '444', b: '...' },
],
'***': [
{ id: 69, text: 'hello, world!!' },
{ id: 187, text: 'fuck the world' },
{ id: 666, text: 'fuck everything' },
],
};
document.body.insertAdjacentHTML('beforeend', arr.map(n => {
const columns = Object.keys(obj[n][0]);
return `
<h1>${n}</h1>
<table>
<thead>
<tr>${columns.map(n => `
<th>${n}</th>`).join('')}
</tr>
</thead>
<tbody>${obj[n].map(row => `
<tr>${columns.map(col => `
<td>${row[col]}</td>`).join('')}
</tr>`).join('')}
</tbody>
</table>`;
}).join(''));
document.body.append(...arr.flatMap(n => {
const columns = Object.keys(obj[n][0]);
const header = document.createElement('h1');
const table = document.createElement('table');
header.textContent = n;
columns.forEach(function(col) {
this.append(document.createElement('th'));
this.lastChild.textContent = col;
}, table.createTHead().insertRow());
obj[n].forEach(function(row) {
const tr = this.insertRow();
columns.forEach(col => tr.insertCell().textContent = row[col]);
}, table.createTBody());
return [ header, table ];
}));
Логика такая, при клике на пункт списка, например "About" этот текст оказывался на месте текущего, а текущий в списке.
dropdown-menu-item
, например. И код в обработчик клика:const item = event.target.closest('.dropdown-menu-item');
if (item) {
const btn = item.closest('.dropdown').querySelector('.dropdown-toggle');
[ btn.textContent, item.textContent ] = [ item.textContent, btn.textContent ];
}