mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-02 04:39:54 -05:00
basic pinia store
This commit is contained in:
33
vue/src/stores/BaseStorePlugin.js
Normal file
33
vue/src/stores/BaseStorePlugin.js
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
|
||||
https://pinia.vuejs.org/core-concepts/plugins.html#adding-new-state
|
||||
|
||||
|
||||
export function BaseStorePlugin () {
|
||||
return {
|
||||
collection: [],
|
||||
item: {},
|
||||
getCollection: function (url) {
|
||||
api.get(url)
|
||||
.then((response) => {
|
||||
this.collection = response.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.handleError(error);
|
||||
});
|
||||
},
|
||||
getItem: function (url) {
|
||||
api.get(url)
|
||||
.then((response) => {
|
||||
this.item = response.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.handleError(error);
|
||||
});
|
||||
},
|
||||
handleError: function (error) {
|
||||
window.alert(error);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user