小编Dom*_* Zi的帖子

nuxt3 自定义类型的简单指南

我有一个 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)

我究竟做错了什么?

typescript vue.js nuxtjs3

3
推荐指数
1
解决办法
2374
查看次数

Typescript 显示“this”对象的错误,提示 TS2532:对象在 vue 方法中可能是“未定义”

由于我对写问题还很陌生,我对可能的错误表示歉意。

问题:我有一个带有打字稿的 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”的使用?

非常感谢大家,祝你有美好的一天!

最好的多姆。

javascript typescript vue.js vuejs3

1
推荐指数
1
解决办法
5733
查看次数

标签 统计

typescript ×2

vue.js ×2

javascript ×1

nuxtjs3 ×1

vuejs3 ×1