我正在尝试显示来自组件的通知。我的组件代码:
<script>
export default {
data () {
return {
}
},
methods:
{
save_data()
{
axios.post(base_url + '/api/settings/save', this.form)
.then(function (response) {
this.$notify({title: 'Saved', message: 'Settings Saved', position: 'bottom-right', type: 'success' });
})
.catch(function (error) {
console.log(error);
});
}
},
}
</script>
但是我遇到错误:Cannot read property '$notify' of undefined
。我在做什么错了?
答案 0 :(得分:1)
您引用的对象错误。在axios回调中使用this
将引用axios帖子。试试这个:
save_data() {
let self = this;
axios.post(base_url + '/api/settings/save', this.form)
.then(function (response) {
self.$notify({title: 'Saved', message: 'Settings Saved', position:
'bottom-right', type: 'success' });
})
.catch(function (error) {
console.log(error);
});
}