davidmszrs / vuexpanded Goto Github PK
View Code? Open in Web Editor NEWBoilerplate-free VueX store module generator
License: GNU General Public License v3.0
Boilerplate-free VueX store module generator
License: GNU General Public License v3.0
Hi David! Very excited to try out vueexpanded inside of my nuxt project but I'm not sure how to set it up. Do you have any documentation? I'm using Nuxt Store Modules...sample code below
// store/jokes.js
const url = "https://icanhazdadjoke.com";
const settings = {
method: "GET",
headers: {
Accept: "application/json",
//,"Content-Type": "application/json"
},
};
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
STATE
Ex - this.$store.state.currentJoke;
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
export const state = () => ({
currentJoke: "This is a Joke",
allJokes: [],
});
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
MUTATIONS
Ex - state.commit("setCurrentJoke", j.joke);
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
// commit
export const mutations = {
// syncrynous
setCurrentJoke(state, payload) {
console.log(state);
state.currentJoke = payload;
state.allJokes.push(payload);
},
};
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
GETTERS
this.joke = this.$store.getters.getCurrentJoke;
OR
...mapGetters("jokes", ["getCurrentJoke", "getAllJokes"]),
joke() {
return this.getCurrentJoke;
},
allJokes() {
return this.getAllJokes;
}
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
export const getters = {
getCurrentJoke: (state) => state.currentJoke,
getAllJokes: (state) => state.allJokes,
};
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ACTIONS
this.$store.dispatch("jokes/setCurrentJoke");
OR
export default {
methods: {
...mapActions("jokes", ["setCurrentJoke"])
},
mounted() {
this.setCurrentJoke();
}
};
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
// dispatch
export const actions = {
// Call nuxtServerInit
async nuxtServerInit({ commit, dispatch }) {
console.log("ACTION - nuxtServerInit");
await dispatch("jokes/initStore"); // Hydrate jokes
},
// Initialize Store
async initStore(state) {
console.log("ACTION - jokes.InitStore");
},
// Call Mutation from Action
async setCurrentJoke(state) {
const joke = await fetch(url, { headers });
const j = await joke.json();
state.commit("setCurrentJoke", j.joke);
},
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.