Warning: preg_grep(): Compilation failed: quantifier does not follow a repeatable item at offset 27 in /var/www/tg-me/post.php on line 75
Frontend | Вопросы собесов | Telegram Webview: easy_javascript_ru/1648 -
Telegram Group & Telegram Channel
🤔 Расскажи о действиях в vuex

В Vuex (хранилище данных в Vue 2 и 3) actions используются для выполнения асинхронных операций, прежде чем изменить состояние (state).

🚩 Как работают actions?

🟠Определение action в `actions`
В actions передаётся объект context, из которого можно вызвать commit() для изменения state.
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment(state) {
state.count++;
}
},
actions: {
asyncIncrement(context) {
setTimeout(() => {
context.commit("increment"); // Вызываем мутацию через 1 сек
}, 1000);
}
}
});


🟠Как вызвать action?
Actions вызываются через dispatch(), а не commit().
store.dispatch("asyncIncrement");


🟠Actions с параметрами
Можно передавать параметры в dispatch(), чтобы использовать их внутри action.
actions: {
asyncIncrement(context, payload) {
setTimeout(() => {
context.commit("increment");
console.log("Задержка:", payload.delay);
}, payload.delay);
}
}

store.dispatch("asyncIncrement", { delay: 2000 });


🟠Возвращение `Promise` в actions
Если action должен дождаться завершения, можно вернуть Promise.
actions: {
fetchData(context) {
return fetch("https://jsonplaceholder.typicode.com/todos/1")
.then(response => response.json())
.then(data => {
console.log("Данные получены:", data);
});
}
}

store.dispatch("fetchData").then(() => {
console.log("Данные загружены!");
});


🟠Использование `async/await` в actions
Можно использовать async/await, чтобы код выглядел чище.
actions: {
async fetchData(context) {
const response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
const data = await response.json();
console.log("Данные:", data);
}
}

await store.dispatch("fetchData");
console.log("Данные загружены!");


🟠Actions могут вызывать другие actions
Если нужно выполнить несколько actions последовательно, можно вызывать один action внутри другого.
actions: {
async firstAction(context) {
console.log("Первый action выполнен");
},
async secondAction(context) {
await context.dispatch("firstAction");
console.log("Второй action выполнен");
}
}

store.dispatch("secondAction");
// Выведет: "Первый action выполнен"
// Затем: "Второй action выполнен"


Ставь 👍 и забирай 📚 Базу знаний
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/easy_javascript_ru/1648
Create:
Last Update:

🤔 Расскажи о действиях в vuex

В Vuex (хранилище данных в Vue 2 и 3) actions используются для выполнения асинхронных операций, прежде чем изменить состояние (state).

🚩 Как работают actions?

🟠Определение action в `actions`
В actions передаётся объект context, из которого можно вызвать commit() для изменения state.

const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment(state) {
state.count++;
}
},
actions: {
asyncIncrement(context) {
setTimeout(() => {
context.commit("increment"); // Вызываем мутацию через 1 сек
}, 1000);
}
}
});


🟠Как вызвать action?
Actions вызываются через dispatch(), а не commit().
store.dispatch("asyncIncrement");


🟠Actions с параметрами
Можно передавать параметры в dispatch(), чтобы использовать их внутри action.
actions: {
asyncIncrement(context, payload) {
setTimeout(() => {
context.commit("increment");
console.log("Задержка:", payload.delay);
}, payload.delay);
}
}

store.dispatch("asyncIncrement", { delay: 2000 });


🟠Возвращение `Promise` в actions
Если action должен дождаться завершения, можно вернуть Promise.
actions: {
fetchData(context) {
return fetch("https://jsonplaceholder.typicode.com/todos/1")
.then(response => response.json())
.then(data => {
console.log("Данные получены:", data);
});
}
}

store.dispatch("fetchData").then(() => {
console.log("Данные загружены!");
});


🟠Использование `async/await` в actions
Можно использовать async/await, чтобы код выглядел чище.
actions: {
async fetchData(context) {
const response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
const data = await response.json();
console.log("Данные:", data);
}
}

await store.dispatch("fetchData");
console.log("Данные загружены!");


🟠Actions могут вызывать другие actions
Если нужно выполнить несколько actions последовательно, можно вызывать один action внутри другого.
actions: {
async firstAction(context) {
console.log("Первый action выполнен");
},
async secondAction(context) {
await context.dispatch("firstAction");
console.log("Второй action выполнен");
}
}

store.dispatch("secondAction");
// Выведет: "Первый action выполнен"
// Затем: "Второй action выполнен"


Ставь 👍 и забирай 📚 Базу знаний

BY Frontend | Вопросы собесов


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/easy_javascript_ru/1648

View MORE
Open in Telegram


Frontend | Вопросы собесов Telegram | DID YOU KNOW?

Date: |

How Does Bitcoin Mining Work?

Bitcoin mining is the process of adding new transactions to the Bitcoin blockchain. It’s a tough job. People who choose to mine Bitcoin use a process called proof of work, deploying computers in a race to solve mathematical puzzles that verify transactions.To entice miners to keep racing to solve the puzzles and support the overall system, the Bitcoin code rewards miners with new Bitcoins. “This is how new coins are created” and new transactions are added to the blockchain, says Okoro.

That strategy is the acquisition of a value-priced company by a growth company. Using the growth company's higher-priced stock for the acquisition can produce outsized revenue and earnings growth. Even better is the use of cash, particularly in a growth period when financial aggressiveness is accepted and even positively viewed.he key public rationale behind this strategy is synergy - the 1+1=3 view. In many cases, synergy does occur and is valuable. However, in other cases, particularly as the strategy gains popularity, it doesn't. Joining two different organizations, workforces and cultures is a challenge. Simply putting two separate organizations together necessarily creates disruptions and conflicts that can undermine both operations.

Frontend | Вопросы собесов from us


Telegram Frontend | Вопросы собесов
FROM USA