Answer the question
In order to leave comments, you need to log in
How to create a function in vuex?
In vuex I added data and a getter to them:
state: {
tree: null, // Json data
},
getters: {
getNode: (state, text) => {
return this.findByText(text);
}
}
getNodeBySlug(slugName, nodes = this.tree) {
const filterFn = ({slug = ""} = {}) => slug.includes(slugName);
for (const node of nodes) {
if (!node.type) {
continue;
}
if (node.type.includes("leaf")) {
if (filterFn(node)) {
return node;
}
}
if (node.type.includes("folder")) {
const result = this.getNodeBySlug(filterFn, node.children);
if (result) {
return result;
}
}
}
},
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