Answer the question
In order to leave comments, you need to log in
How to call a Vue.JS function?
Hello everyone,
I am a beginner programmer in this field, I have a question,
is there a javascript file that contains the following function:
export const actions = {
async loadFunction({ commit }) {
try {
const plans = await Parse.Cloud.run('getFunction', {}, {});
commit('setFunction', plans);
} catch (error) {
commit('setFunction', null);
return null;
}
},
};
<TItem
v-for="
(index, item) in ?????
:key="index"
:tplan="item"
@delete="deleteItem(index)"
/>
Answer the question
In order to leave comments, you need to log in
// store
export const state = () => ({
functions: []
});
export const actions = {
async loadFunction({ commit }) {
try {
const plans = await Parse.Cloud.run('getFunction', {}, {});
commit('setFunction', plans);
} catch (error) {
commit('setFunction', null);
return null;
}
},
};
export const mutations = {
setFunction: (state, payload) => {
state.functions = payload;
}
}
// Ваш копонент, где вы отображаете TItem
<template>
<div>
<TItem
v-for="(item, index) in functions"
:key="index"
:tplan="item"
@delete="deleteItem(index)"
/>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
//....
computed: {
...mapState([
'functions'
])
}
//...
}
</script>
Apparently it was not you who wrote this and it was taken out of context, or rather the vuex store.
In addition to actions, there should be state, mutations.
This function will not work in this form.
If it receives data, then a setFunction mutation is created that changes the state. Next, it is desirable to create a getter (conditional getData) that will return data to you.
And in the component, you create a calculated property with a suitable name and use the getter to get the data.
And this property is specified in the loop.
Everything is just
P.S. while writing - Dmitry just depict everything)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question