【问题标题】:How to get response from other file request response in Laravue如何从 Laravel 中的另一个文件请求响应中获取响应
【发布时间】:2020-03-14 14:33:22
【问题描述】:

我正在尝试从 File2.vue 获取响应并将其传递回 File1.vue。我正在使用 VueJS v1.0.28,如何从其他文件请求响应中获取响应?

File1.vue

   File2.updateNotice(this,{'id':id}).then((response) => {
      console.log("response from File2  :",response)
   }); 

File2.vue

updateNotice(context,params) {
            let url = staff_service.STAFF_NOTICES_READ_RESOURCE;
            Vue.http.post(
                url,
                params
            ).then(response => {
                return response;
            }) 
}

来自 File1 的错误响应:

Cannot read property 'then' of undefined

【问题讨论】:

  • 您的问题是什么?请清楚。你已经安慰了你的反应。
  • 我想从 File2.vue 获取响应并传回 File1.vue。
  • 你可以使用 vuex,将响应传递给 state。在file1.vue 中检查状态变化并获取file.vue 中的值
  • 您需要在 Vue.http.post 之前添加一个 return 以将承诺返回给调用者 - 否则,您将不会从 updateNotice 返回任何内容,因此 then 未定义
  • @steve16351 OH MY !"#$%&'(!!!!!! 我的错,谢谢!我现在能得到回复忘了放一些返回声明。节省我很多时间.

标签: laravel api vue.js request http-post


【解决方案1】:

现在解决了,添加了一个

返回

之前

Vue.http.post(

File2.vue

File1.vue

   File2.updateNotice(this,{'id':id}).then((response) => {
      console.log("response from File2  :",response)
   }); 

File2.vue

updateNotice(context,params) {
            let url = staff_service.STAFF_NOTICES_READ_RESOURCE;
            return Vue.http.post(
                url,
                params
            ).then(response => {
                return response;
            }) 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多