我有一个 vue 文件,我想在其中使用自定义类型:
/*
file: /components/Grid.vue
*/
<script setup>
// define Section type
interface Section {
type: string;
img: string;
heading: string;
content: string;
}
const props = defineProps < {
sections: Section[],
baseUrl: string
} > ();
const sections = ref(props.sections);
const baseUrl = ref(props.baseUrl);
</script>
Run Code Online (Sandbox Code Playgroud)
它抛出ERROR [@vue/compiler-sfc] Unexpected reserved word 'interface'. (3:0) 。
我究竟做错了什么?
由于我对写问题还很陌生,我对可能的错误表示歉意。
问题:我有一个带有打字稿的 vue 应用程序。
export default {
methods: {
setProgram: (program: Program)=>{
this.program = program // TS2532: Object is possibly 'undefined'.
this.step++ // TS2532: Object is possibly 'undefined'.
}
},
...
}
Run Code Online (Sandbox Code Playgroud)
虽然我真的很喜欢打字稿的这个功能,但我真的确信,在这种情况下“this”不会是未定义的。
我怎样才能让打字稿平静下来关于“this”的使用?
非常感谢大家,祝你有美好的一天!
最好的多姆。