admin管理员组文章数量:1332715
So I've got a ts file with the following code as my starter:
import { defineComponent } from 'vue';
type Forecasts = {
date: string,
temperatureC: string,
temperatureF: string,
summary: string
}[];
interface Data {
loading: boolean,
post: null | Forecasts
}
export default defineComponent({
data(): Data {
return {
loading: false,
post: null
};....
and this is referenced in my vue component with
<script lang="ts" src="../scripts/Forecast.ts"></script>
The Forecasts type is really a model and to follow seperation of concern, I want to move that out of this ts file and into its own as I may want to use the model in a number of places and fo not want to duplicate (I'll probably want to do the same with the interface as well).
How should I declare my Forecasts type in another ts file and how can I then reference it in this file?
So I've got a ts file with the following code as my starter:
import { defineComponent } from 'vue';
type Forecasts = {
date: string,
temperatureC: string,
temperatureF: string,
summary: string
}[];
interface Data {
loading: boolean,
post: null | Forecasts
}
export default defineComponent({
data(): Data {
return {
loading: false,
post: null
};....
and this is referenced in my vue component with
<script lang="ts" src="../scripts/Forecast.ts"></script>
The Forecasts type is really a model and to follow seperation of concern, I want to move that out of this ts file and into its own as I may want to use the model in a number of places and fo not want to duplicate (I'll probably want to do the same with the interface as well).
How should I declare my Forecasts type in another ts file and how can I then reference it in this file?
Share Improve this question asked Nov 20, 2024 at 17:40 bilporbilpor 3,9316 gold badges38 silver badges85 bronze badges 3 |1 Answer
Reset to default 0Finally figured it out.
In the seperated file, the type needs to be declared with export :
export type Forecasts = {
date: string,
temperatureC: string,
temperatureF: string,
summary: string
}[];
then to call I need to add 'type' to the declaration:
import type { Forecasts } from 'src/models/models';
本文标签: new to vuejs how do i seperate my models from a componentStack Overflow
版权声明:本文标题:new to vue.js how do i seperate my models from a component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742340052a2456416.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
import { Forecasts } from 'models';
and it did not like it, hence my question, how do I declare this in another file and declare it for use in this one. – bilpor Commented Nov 21, 2024 at 9:09