Vue js“在获取请求时无法读取未定义的属性'获取'

时间:2016-03-07 10:06:38

标签: javascript laravel vue.js

此错误出现在post和get请求的日志中。我正在使用laravel 5并在页面底部按顺序提取了vuejs和vue-resource。但由于某些原因,使用Runnable expensiveTask = () -> { // expensive operations that should not run on the application thread Match msg = stablishSearchConditions(); TreeItem<String> root = new TreeItem<>("ROOT"); int indexName = 1; String mensaje = "Mensaje "; for (Match message : msg.each()) { TreeItem<String> nodo = new TreeItem<String>(mensaje + indexName); root.getChildren().add(nodo); root.setExpanded(true); String mens = message.getMessage(); TreeItem<String> nodo2 = new TreeItem<String>(mens); nodo.getChildren().add(nodo2); indexName++; } // update ui -> application thread Platform.runLater(() -> { treeLabelResults.setText(""); arbol.setRoot(root); dialog.close(); }); }; // start new thread for expensiveTask new Thread(expensiveTask).start(); this.$http.get发出任何请求都会在标题中返回错误。

脚本

this.$http.post

Js / app.js代码

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.10/vue.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/0.7.0/vue-resource.min.js"></script>
    <script src="js/jquery.easing.min.js"></script>
    <script src="js/scrolling-nav.js"></script>
    <script src="js/app.js"></script>

2 个答案:

答案 0 :(得分:2)

您正在尝试将this用于jQuery回调。您需要先引用它并使用引用,如下所示:

openModal: function(){
    var instance = this;
    $('td').on('click', function(){
        if($(this).hasClass('not-month'))
        {

        }
        else
        {
            var year = '2016';
            var month = $(this).parent().parent().parent().parent().find('h4').text();
            var day = $(this).text();
            console.log(day + ' ' + month + ' ' + year);

            instance.$http.get('/test', function(response){
               instance.$set('test', response);
            });

        }
    });
}

答案 1 :(得分:0)

在组件导出默认中只需粘贴以下代码。

import _Vue from 'vue';
import _VueResource from 'vue-resource';

// vue use vueResource for http request.
_Vue.use(_VueResource);

export default {
name :  'SearchField',
_this: this,
data() {
  return {
    contactNumber: []
  }
},
methods: {
  GetContact: function () {
    // GET /someUrl
    return this.$http.get('localhost:8081').then(response => {

      // get body data
      let someData = response.body;
      alert(someData);

    }, response => {
      // error callback
      alert("error")
    }).bind(_this);
  }
}
};