Skip to content

Instantly share code, notes, and snippets.

View LORD-KAY's full-sized avatar
🎯
Focusing

Lord Kay LORD-KAY

🎯
Focusing
View GitHub Profile
@LORD-KAY
LORD-KAY / index.js
Last active November 9, 2021 07:33
A sample index.js depicting the vuex code structure and definitions
const state = {
todos: []
}
const mutations = {
ADD_TODO(state, payload) {
state.todos.push(payload)
}
}
@LORD-KAY
LORD-KAY / main.js
Last active August 18, 2020 22:59
the main.js file inside the root directory of a vue js project that initialise the vue instance and uses other third party plugins
// Path may change depending on where you created the store configurations
import store from "./index.js"
new Vue({
store,
//..other plugins here
}).$mount("#app")
@LORD-KAY
LORD-KAY / Todo.vue
Last active August 19, 2020 10:10
Vue JS Component implementing a simple dispatch action for vuex store
<template>
<div>
<input type="text" v-model="todo" name="todo" id="addtodo"/>
<button @click="addTodo">Add New Todo</button>
</div>
</template>
<script>
export default {
name: "Todo",
data() {
@LORD-KAY
LORD-KAY / get_store_items_from_state.vue
Last active January 9, 2023 09:21
Get a state value directly from a vuex store without using getters
<template>
<div>Item from store without getters</div>
<h3>{{ $store.state.name }}</h3>
</template>
<script>
export default {
data: () => ({
name: ''
})
@LORD-KAY
LORD-KAY / get_store_items_from_getter.vue
Last active January 9, 2023 09:46
Get a vuex store state value using getters
<template>
<div>
<h1>All todo items </h1>
<div v-for="(item,index) in $store.getters['getAllTodos']" :key="index">
<span>{{ item }}</span>
</div>
</div>
</template>
<script>