【问题标题】:cannot read property 'default' of undefined无法读取未定义的属性“默认”
【发布时间】:2018-03-30 17:10:35
【问题描述】:

在下面的 this.realm = 行上收到此错误。不知道为什么这个代码在被格式化为工厂函数时会起作用

import Realm from 'realm';

export default function Db() {
    this.realm = new Realm({
        schema: [Wallet, WalletAddress, WalletTransaction, Log, APIWallet, APITransaction, APIAccount, Configuration],
        path: config.db_path
    });
    logger(2, realm.path);
}

Db.prototype.doOneToMany = function(one, many) {..};

Db.prototype.query = function(model, filter) {..};

Db.prototype.insert = function(model, options) {..};

Db.prototype.del = function(model, obj) {..};

Db.prototype.update = function(obj, options) {..};

Db.prototype.write = function(func) {..};

Db.prototype.close = function() {..};

错误

【问题讨论】:

    标签: javascript react-native realm


    【解决方案1】:

    尝试删除“默认”关键字,它会正常工作...

    export function Db() {
    this.realm = new Realm({
        schema: [Wallet, WalletAddress, WalletTransaction, Log, APIWallet, APITransaction, APIAccount, Configuration],
        path: config.db_path
    });
    logger(2, realm.path);}
    

    试试这个...

    【讨论】:

    • 那行不通。抛出一个新错误_Db2.default is not a constructor
    猜你喜欢
    • 2020-05-23
    • 2021-12-18
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 2020-04-06
    • 2020-10-30
    相关资源
    最近更新 更多