我对 JS 和 TS 还很陌生,但由于 Ionic 应用程序框架,我正在正确地学习它。我正在按照文档中的官方教程进行操作,但遇到了问题。
我有两个文件 usePhotoGallery.ts
和 tab2.vue
。在 usePhotoGallery.ts
中,我们为箭头函数 takePhoto()
定义并导出包装函数:
export function usePhotoGallery() {
const takePhoto = async () => {
const cameraPhoto = await Camera.getPhoto({
resultType: CameraResultType.Uri,source: CameraSource.Camera,quality: 100
});
};
return {
takePhoto
};
}
在 tab2.vue
中,我们像这样导入该函数:
import { usePhotoGallery } from './usePhotoGallery'
教程现在说“从 usePhotoGallery 中解构 takePhoto”,如下所示:
const { takePhoto } = usePhotoGallery();
执行此操作时,我收到一条错误消息:
[vue-cli-service] TS2339:类型上不存在属性“takePhoto” '() => 承诺'。
当我删除大括号并写入 const takePhoto = usePhotoGallery();
时,一切正常。
这是教程页面的链接:https://ionicframework.com/docs/vue/your-first-app/2-taking-photos
有人能解释一下这里发生了什么吗?
非常感谢!