【问题标题】:How to use sweetalert2 in nuxt with typescript?如何在带有打字稿的nuxt中使用sweetalert2?
【发布时间】:2021-11-22 12:12:26
【问题描述】:

之前我在没有配置 typescript 的情况下配置了我的 nuxt 项目,所以我根据这个文档为 nuxt 安装了 sweetalert2: https://www.npmjs.com/package/nuxt-sweetalert2 一切正常,然后我在同一个项目中设置了打字稿,我在 sweetalert 中有错误

我得到的错误是:

 Property '$swal' does not exist on type 'CombinedVueInstance<Vue, { dinamic: { message: string; }; addFile: boolean; fields: { key: string; label: string; sortable: boolean; }[]; loading: boolean; dialogVisible: boolean; title: string; message: string; reason: boolean; ... 28 more ...; html: string; }, { ...; }, { ...; }, Readonly<...>>

我的使用方式是:

this.$swal({
  title: "Has been deleted",
  text: "the record you are accessing no longer exists",
  type: "warning",
  confirmButtonText: "OK"
});

我在nuxt中对typescript的配置是这样的:https://typescript.nuxtjs.org/es/guide/setup/

【问题讨论】:

  • dinamic?是不是哪里打错字了?
  • 我的组件中有几个打字稿错误,我正在纠正这些错误,但我不知道这个错误可能在哪里,或者我不知道是否应该配置一些打字稿
  • 谢谢,我没有在“vue-sweetalert2”类型中添加tsconfig.json

标签: typescript nuxt.js sweetalert2


【解决方案1】:

执行此设置:https://www.npmjs.com/package/vue-sweetalert2 在额外的 nuxt 部分中,您需要添加到

//tsconfig.json
"types": [
    "vue-sweetalert2"
  ],

【讨论】:

    猜你喜欢
    • 2020-01-14
    • 2022-10-21
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2022-11-27
    • 1970-01-01
    相关资源
    最近更新 更多