5-dynamic-methods-event
const SURVEY_INFO_STATE = {
surveyName: '',
startDate: '',
startTime: '',
endDate: '',
endTime: '',
surveyOrgan: '',
surveyDescription: '',
};data: vm => ({
...SURVEY_INFO_STATE,
}),Last updated
const SURVEY_INFO_STATE = {
surveyName: '',
startDate: '',
startTime: '',
endDate: '',
endTime: '',
surveyOrgan: '',
surveyDescription: '',
};data: vm => ({
...SURVEY_INFO_STATE,
}),Last updated
const surveyInfoMethods = {};
Object.keys(SURVEY_INFO_STATE).forEach(stateName => {
surveyInfoMethods[`handleChange${capitalizeFirstLetter(stateName)}`] = function (v) {
this[stateName] = v;
this.$eventBus.$emit(`change-${stateName}`, v);
};
});methods: {
...surveyInfoMethods,
},export const capitalizeFirstLetter = (string = '') => {
return string.charAt(0).toUpperCase() + string.slice(1);
}Object.keys(SURVEY_INFO_STATE).forEach(stateName => {
this.$eventBus.$on(`change-${stateName}`, v => {
this[stateName] = v;
})
});