Scenario:
I am currently working on a project where I am implementing mixins to engage with data from components and other methods. Despite the code functioning as expected, I am encountering errors in Vetur indicating that the method does not exist in the combined vue instance. This has led to linting errors in my project, causing concerns about the overall code quality. The complaints are also reflected in the ts-lint console, adding to the uncertainty surrounding the project.
Queries and Expectations
What is causing these errors and how can I resolve them? The recurring nature of these errors across components utilizing the same code is making the use of mixins for code reusability more complex than anticipated.
Specifics and Code Snippets
Vue Component Implementation with Mixin
export default Vue.extend({
name: 'RecentRequests' as string,
data() {
return {
requests: [] as Request[],
workflows: [] as Workflow[],
environment: `${process.env.VUE_WEB_API}`,
search: '',
}
},
async created() {
await RequestService.getRequest().then((response) => {
this.$data.requests = response.Data;
}).catch((err) => {
this.$data.requests = null;
this.$data.topFive = null;
this.$store.dispatch('updateErrorMessage', {message: `${err}`});
this.$store.dispatch('updateError');
});
await WorkflowService.getWorkflow().then((response) => {
this.$data.workflows = response.Data;
}).catch((err) => {
this.$data.requests = null;
this.$data.topFive = null;
this.$store.dispatch('updateErrorMessage', {message: `${err}`});
this.$store.dispatch('updateError');
});
},
mixins: [globalMixins],
computed: {
filteredRequests() {
let searchTerm = this.search.toLowerCase();
let topFive: any = this.topFive()
if(this.search === null || this.search === '') {
return topFive
} else {
return topFive.filter((item: any) => {
return item.WorkflowDisplayName.toLowerCase().includes(searchTerm);
});
}
}
},
methods: {
topFiveRequests() {
// combine workflows first before running
this.combineRequestsAndWorkflows(this.$data.requests, this.$data.workflows);
// make copy of requests array
const requestsCopy = this.$data.requests.map((x: Request) => x);
// sort array by most recent
const mostRecentRequests = requestsCopy.sort((a: any, b: any) => {
const dateA: any = new Date(a.timeRequested);
const dateB: any = new Date(b.timeRequested);
return dateB - dateA;
});
const result = mostRecentRequests.splice(0, 4);
return result;
},
},
})
</script>
Error Highlighted by Vetur
https://i.sstatic.net/xnxGE.png
Error Indicated by tsLint in the Console
https://i.sstatic.net/dH34R.png
I