首页 > 解决方案 > 未捕获的类型错误:无法读取未定义的属性“振动”

问题描述

下午好,对不起,我的英语不好,我的离子电容器有问题,我正在尝试使用插件 Vibration,文档没有描述太多东西,但我从 android studio 的终端收到这条消息

错误:

在此处输入图像描述

这是我的代码:

import { Plugins, CameraResultType } from '@capacitor/core';
import { Vibration } from '@ionic-native/vibration/ngx';

const { Camera } = Plugins

interface Props extends React.Props<ControlVibratorComponent> {

}

export default class ControlVibratorComponent extends React.Component<Props>{

    constructor(props: any, private vibration: Vibration) {
        super(props);
    }

    changeNotificationState(e: any) {
        if (e.detail.value > 0) {
            console.log('vibrando');
            // this.vibration.vibrate([2000, 1000, 2000]);
            // console.log(this.vibration);
            this.vibration.vibrate(2000);
        } else {
            console.log('stop');
            this.vibration.vibrate(0);
        }
    }
}

标签: typescriptionic-frameworkcapacitor

解决方案


如果您使用 Capacitor 构建应用程序,最好尽可能使用电容器插件。对于振动,您可以使用电容器Haptics 插件


推荐阅读