我想用laravel和vuejs发送电子邮件。我像下面这样写了laravel控制器函数
Mail::send(['text' => 'mail'],['name', 'David'], function($message){
$message->to('test123@gmail.com')->subject('Test Email');
$message->from('testmail@gmail.com', 'David');
});
return response()->json(['success'=>true]);
我为@click方法写了一个vuejs send email函数
this.axios.get('https://techwizlanka/send', {
body: JSON.stringify(this.user),
headers: {
'content-type': 'application/json',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
.then(res => res.json())
.then(data => {
console.log("email sent");
})
.catch(err => console.error(err.toString()));
我将这个URL命名为
Route::get('/send', 'MailController@sendMail');
但是当单击“发送”按钮时,它会显示此错误消息。
app.js:44786未捕获TypeError:无法在VueComponent.sendMail (app.js:44786)的invoker (app.js:34769)的HTMLButtonElement.fn._withTask.fn._withTask (app.js:34568)读取未定义的属性“”get“”
有人能帮我解决这个问题吗?基本上,我想在提交带有laravel和vuejs的表单时发送电子邮件。
发布于 2019-01-18 14:50:25
这绝对是因为您没有正确地调用axios
。请确保this.axios
上的this
指的是什么。
假设您使用npm install axios
安装了axios。然后尝试导入和使用axios,大致如下所示:
import axios from 'axios';
export default {
data() {
return {
user: [],
};
},
methods: {
click() {
axios
.get('https://techwizlanka/send', {
body: JSON.stringify(this.user),
headers: {
'content-type': 'application/json',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
})
.then(res => res.json())
.then(data => {
console.log("email sent");
})
.catch(err => console.error(err.toString()));
},
},
...
}
发布于 2019-05-29 08:49:36
尝试使用此方法
axios.post(url, data)
.then(response => {
})
并在route/web.php中发布您的路由
在使用get方法函数时,不需要请求,但在您的情况下,您需要传递请求。
https://stackoverflow.com/questions/54248213
复制相似问题