您好如何使用打字稿将该组件转换为基于类的组件?
<script>
import { Line } from 'vue-chartjs'
import { chartLast30Days, chartStylingMethods } from '#/mixins'
import { myChartOptions } from '#/const/charts'
export default {
extends: Line,
mixins: [chartLast30Days, chartStylingMethods],
props: { chartPointsDownloads: Array, chartPointsPlays: Array, chartPointsSales: Array },
}
</script>
答案 0 :(得分:5)
我可以为您提供一些代码示例,以使用vue属性装饰器创建基于类的组件,扩展类并使用mixins。
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
@Component
export default class MyClass extends Vue {
created() {
console.log("Created MyClass");
}
}
</script>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import MyClass from './MyClass';
@Component
export default class MyExtendingClass extends MyClass {
created() {
console.log("Created MyExtendingClass");
}
}
</script>
import Vue from 'vue'
import Component from 'vue-class-component'
@Component
export default class MyMixin extends Vue {
myMixinValue = 'Fetch my mixin';
}
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import MyClass from './MyClass';
import MyMixin from './MyMixin';
@Component({
mixins: [MyMixin]
})
export default class MyExtendingClass extends MyClass {
created() {
console.log("Created MyExtendingClass");
console.log(this.myMixinValue);
}
}
</script>