Reputation: 415
I use Vue JS 2 and typescript for my project. I want to import data.ts, methods.ts, props.ts in my customComponent.vue:
<!-- ////////////////////////////////////////////////////////////////////// -->
<script lang="ts">
import Vue from "vue";
import data from './data'
import props from './props'
import methods from './methods'
import { created, mounted } from './vue-hooks'
export default Vue.extend({
name: "custom-component"
});
</script>
How can write these typescript files in order to be imported correctly in the Vue custom component?
Upvotes: 0
Views: 168
Reputation: 14211
You should be able to just move the code from the component to each different file and export them as default.
An example for data
below:
// data.ts
const data = function() {
return {
//data here
}
}
export default data
And then use it in the component
export default Vue.extend({
name: "custom-component",
data
});
But I would strongly discourage this. You should split your code based on concerns not on structure of the objects. Navigating between all this components for the simplest of tasks will be a great pain.
Upvotes: 1