![](/img/trans.png)
[英]How do I resolve "[ERR_REQUIRE_ESM]: Must use import to load ES Module" when using D3.js 7.0.0 with Next.js 11.0.1?
[英]How do I import and use module using core JS in NativeScript
我是NativeScript的新手,正在嘗試使用FancyAlert NPM模塊:
https://github.com/NathanWalker/nativescript-fancyalert
在自述文件中,他們展示了一個使用TypeScript的非常簡單的示例,如下所示:
import { TNSFancyAlert, TNSFancyAlertButton } from "nativescript-fancyalert";
.
.
.
public showSuccess() {
TNSFancyAlert.showSuccess(
"Success!",
"Fancy alerts are nice.",
"Yes they are!"
);
}
在他們的XML文件中,他們像正常一樣簡單地調用它:
<Button text="Alert Success" tap="{{showSuccess}}" />
所以我不使用TypeScript。 我無法獲得此簡單的警報來工作。 我努力了:
在我的main-view-model.js中
const fancyAlert = require("nativescript-fancyalert");
.
.
.
fancyAlert.showSuccess(
"Success!",
"You are logged in.",
"Success!"
);
不工作。
誰能幫助我使用核心JS使用此模塊?
謝謝。
試試: fancyAlert.TNSFancyAlert.showSuccess()
。
[編輯]這確實應該起作用,因為它反映了Narendra Mongiya在您的問題中所鏈接的問題文件中給出的解決方案。 要記住的一件事是它是一個Promise,所以讓我們在其中添加catch()
塊以揭示任何錯誤。
const fancyAlert = require("nativescript-fancyalert");
// ...
fancyAlert.TNSFancyAlert.showSuccess(
"Success!",
"You are logged in.",
"Success!"
)
.then((resolution) => {
console.log("[TNSFancyAlert] showSuccess() succeeded.", resolution);
})
.catch((error) => {
console.error("[TNSFancyAlert] showSuccess() failed.", error);
});
您可能還會發現只是在錯誤的代碼位置調用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.