【发布时间】:2017-11-25 09:57:10
【问题描述】:
我正在使用 Laravel 5.5、Vue 2 和 Vuex 创建系统注释。 我不能发表评论。我进入控制台,出现两个错误:
TypeError:this.addComment 不是函数
错误:请求失败,状态码为 422
这是我的代码:
import { addComment } from '../../store/actions'
export default {
computed: {
addComment
},
vuex: {
actions: { addComment }
},
data () {...},
methods: {
sendComment: function () {
this.addComment({
commentable_id: this.id,
commentable_type: this.model,
content: this.content,
reply: this.reply
})
}
actions.js 代码
export const addComment = function ({dispatch}, comment) {
return axios.post('/comments', comment).then((response) => {
dispatch('ADD_COMMENT', response.data)
})
};
我所有的路由、控制器和突变都经过测试并且运行良好。
【问题讨论】:
标签: javascript laravel-5 vuejs2 axios vuex