获得调用函数后的计算能力?

时间:2018-07-11 19:33:21

标签: vue.js

以下是复制过去的示例,如果将其保存在index.html文件中,它将起作用:

我需要访问myvalue{{my_dates['2018-07-10']['april']}}

这是我的完整代码:

<!DOCTYPE html>
<html>
<head>
    <title>test</title>
    <script src="https://unpkg.com/vue"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue-resource@1.5.1"></script>
</head>
<body>

<div id="app">
    <!-- I need to get access to myvalue from computed -->
  <p>{{ myvalue }}</p>
  <p>{{ mess }}</p>

  <!-- trying to print values from here -->
 <p>{{my_dates['2018-07-10']['april']}}</p>
 <p>{{my_dates['2018-07-10']['may']}}</p>
</div>

</body>

<script>
    var app = new Vue({
  el: '#app',
  data: {
    my_dates: {},
    mess: 'hello world'
  },
    computed: {
        // 
      myvalue: function () {
        return Number(this.my_dates['2018-07-10']['april']) + Number(this.my_dates['2018-07-10']['may'])
      }
    },

    methods: 
    {
      getTableData: function()
      {
          // GET /someUrl
          this.$http.get('http://dlang.ru/test').then(response => {
            // get body data
            this.my_dates = response.body;

          }, response => {
            // error callback
          });
      }
    },

    created: function(){
        this.getTableData()
    }

})

</script>
</html>

我无法显示myvalue并获得Cannot read property的问题

0 个答案:

没有答案