以下是复制过去的示例,如果将其保存在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
的问题