如何从Laravue中的其他文件请求响应中获取响应

时间:2019-11-19 06:24:32

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

我正在尝试从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

1 个答案:

答案 0 :(得分:0)

现在解决了,添加了一个

  

返回

之前

  

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;
            }) 
}