简体   繁体   中英

using an import statement inside a Blazor / Javascript file?

I'm trying to use idb idb inside a Javascript file in a Blazor project. Any js file that the Blazor app connects to lives in the window.xxx environment. For example the js file starts like this:

window.reportDBFunctions = {
    //<script type="module" src="https://cdn.jsdelivr.net/npm/idb@7/build/umd.js"></script >
    initReportDB: (name, version) => {
        let db;

        const reportDB = name + "DB";
        db = openDb(reportDB, version, db => {
            if (db.version == 0) {
                db.createObjectStore(name, { keyPath: "rptName" });
                return;
            }
        });

but to use idb, which is commented out on line 2 above, I need to import the module.

I have put the line above and below the windows.reportDBFunctions line. I have changed the file to a normal script file with functions defined, I have moved the functions into a SomeBlazorfile.razor.js file, (I didn't know you could do that.)

I have added the import into the index.html file which is wrong because it loads it for Blazor not the Javascript files.

Everything just throws errors regarding syntax, both compile time and runtime.

Thanks

Craig

Ugh I feel so dumb.

I am running the latest idb (7.1.1) but the example I was following was 3.0.2 Lots of breaking changes between the two versions.

Carry on people.

Craig

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM