Answer the question
In order to leave comments, you need to log in
How to properly write and store Vue.js modules used in a project?
There is a Vuex data store in which I have an action that makes a request to a third-party api, returns data and launches a callback function, but it seems to me that this whole action is rather cumbersome (all code is taken from the api developer's website) and extremely inconvenient in terms of the logic of a particular storage module (this method is not at ease). Since this method (action) will need to be used in several components, with different input parameters, I decided to put it in a separate module and use it like this: so that later I can work with it like this:import exampleapi from 'example-api';
exampleapi.query('{}',function(data){
//some actions
})
// lib/counter.js
var counter = 1;
function increment() {
counter++;
}
function decrement() {
counter--;
}
module.exports = {
counter: counter,
increment: increment,
decrement: decrement
};
// src/main.js
var counter = require('../../lib/counter');
counter.increment();
console.log(counter.counter); // 1
-store
|--modules
|----invites.js
|----user.js
|--index.js
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question