javascript - 如何在 Vue.js 中使用 SMTP.js - 导入外部脚本
问题描述
Helle,我在 Vue.js 中使用 smtp.js 及其外部脚本时遇到问题。问题是 mail.js,但我无法将外部脚本加载到我的 vue 组件中。然后尝试使用 vue-plugin-load-script for npm 解决这个问题,但这对我不起作用。我的 Vue 组件:
<template>
<v-container class="mt-10">
<v-card max-width="400px" class="mx-auto mt-5">
<v-card-title>If You've got a question?</v-card-title>
<v-card-subtitle>Type it in below!</v-card-subtitle>
<v-card-text>
<v-text-field label="Your Name" v-model="name"></v-text-field>
<v-text-field label="Your Email" type="email" v-model="email"></v-text-field>
<v-textarea label="Your Message" counter="100" maxlength="100" auto-grow outlined v-model="message"></v-textarea>
</v-card-text>
<v-card-actions>
<v-btn class="mx-auto mb-4 success" @click="sendEmail">Send Message</v-btn>
</v-card-actions>
</v-card>
</v-container>
</template>
<script>
export default {
name: 'Contact',
data: () => ({
email: "",
message: "",
name: "",
}),
methods: {
sendEmail(){
this.$loadScript("https://smtpjs.com/v3/smtp.js")
.then(Email => { //this Promise return nothing!!!
Email.send({
SecureToken : "3df7ff95-181c-4f27-9e94-ee2cfc280818",
To : 'mail@example.com',
From : this.email,
Subject : this.name,
Body : this.message,
}).then(
message => alert(message)
);
})
.catch(() => {
// Failed to fetch script
});
},
},
}
</script>
vue-plugin-load-script 在 main.js 中导入,如下所示:
import LoadScript from 'vue-plugin-load-script';
Vue.use(LoadScript);
我希望你能帮我解决这个问题。谢谢。
解决方案
推荐阅读
- kotlin - Kotlin 文档中未解决的@sample
- html - 将 div 的高度设置为另一个 div 高度
- android - 如何在 MVVM 中进行新的网络调用?
- ios - 当我按下按钮时 UIView 到图像
- python - Python DataFrame:如何用一个特定位置的值替换 Nan
- java - 如何在Java中遍历json文件
- git - 在 Smart Git 中设置 SSH 客户端
- python - 在 Python 中,如何将整数 19 附加到两位数年份的列表中?
- javascript - ModuleWithProviders
需要 1 个类型的参数 - angular-autofocus-fix - python - 使用python从bseindia下载csv文件