【发布时间】:2019-12-02 02:36:55
【问题描述】:
我对 Vue 有点陌生,我正在尝试弄清楚如何从组件的计算值中访问计算值。 请查看这个小提琴:https://jsfiddle.net/85ma3rct/
<script src="https://unpkg.com/vue"></script>
<div id="app">
<table>
<floor></floor>
<floor></floor>
<floor></floor>
</table>
Largest area: {{ largest_area}}
</div>
Vue.component('floor', {
data: function () {
return {
width: 20,
height: 20
}
},
computed: {
area: function () {
return this.width * this.height;
}
},
template: '<tr><td><input type="number" v-model="width"></td>' +
'<td><input type="number" v-model="height"></td>' +
'<td>{{ area }}</td>' +
'</tr>'
})
new Vue({
el: '#app',
computed: {
largest_area: function () {
// How to get this from component computed values...
return 0
}
},
})
如何从多个组件中通过计算值获得最大面积计算值?
【问题讨论】:
标签: vue.js