2017-02-10 64 views
0

我正在使用新Laravel 5.4的Vue模板。在我的Office.vue我有这个代码。Laravel 5.4和Vue 2.0.1无法读取未定义的属性'get'

<template> 
    <div class="container"> 
     <div class="row"> 
      <div class="col-md-8 col-md-offset-2"> 
       <div class="panel panel-default"> 
        <div class="panel-heading">Example Component</div> 

        <div class="panel-body"> 
         I'm an example component! {{ message}} | {{ type}} | {{ number }} 
        </div> 
        <span id="vue"></span> 
       </div> 
      </div> 
     </div> 
    </div> 
</template> 

<script> 
    export default { 
     mounted() { 
      return this.displayOffices(); 
     }, 
     data: function(){ 
      return { 
       message: "aw", 
       type: "test", 
       number: 2 
      } 
     }, 
     methods: { 
      displayOffices: function(){ 
       this.$http.get('/vueOffice', function(course) { 
        console.log(course); 
       }); 
      } 
     } 
    } 
</script> 

显示的数据是好的,很好的工作,但我得到的错误与

Uncaught TypeError: Cannot read property 'get' of undefined

这是此。$ http.get

我试图做到的是从返回JSON数据的路线获取数据。

我需要帮助解决这个错误,一直试图寻找答案,但每个人都用不同的方式来实现Vuejs。

+1

如果您正在使用'axios'而不是'vue-resource'然后r使用'axios'放置'this。$ http'。 – mrabbani

+0

您好我可以标记该所接受,感谢 – Ikong

回答

1

如果您正在使用的axios代替vue-resource然后用axios替换this.$http

1

您必须安装vue-resource可以使用this.$http.get

,或者你可以安装axios和使用axios.get代替this.$http.get

+0

我有安装VUE资源,并重新建立,但仍存在问题,我用爱可信现在,它的工作的伟大 – Ikong

0

不推荐使用此之前,$ http.get为Vue的希望远离支持它。他们建议使用使用axios的库。然后您可以使用this.axios.get()

self.axios 
    .get(apiUrl, { 
    params: this.formData, 
    }) 
    .then((response) => { 

    }); 
0

另一种方法是将以下代码添加到您的文件:

Vue.prototype.$http = axios; 
+0

不,不这样做。你为什么?这是非常糟糕的做法 –

0

添加此require('vue-resource');在文件中


/resources/assets/js/bootstrap.js

后:

window.Vue = require('vue');

相关问题