【发布时间】:2021-04-02 14:22:10
【问题描述】:
我有一个返回一个数组值的方法。我希望在 HTML 文件中,此标签 p 具有方法的值并更新您的值。问题是:HTML 不更新,为什么?如果使用console.log,值正常出现...
HTML
<div id="app">
<button @click="test($event, 5, 10)">Generic Button</button>
<!--here, the value doesn't appear-->
<p style="background-color: blue">Test value: {{returnValueVector()}}</p>
</div>
JS
var app = new Vue({
el: '#app',
data: {
actions: [],
counter: 0,
},
methods: {
returnValueVector() {
return this.actions[this.counter]
},
test(event, max, min) {
this.counter++
this.actions.push(Math.floor(Math.random() * max) + min)
}
}
});
【问题讨论】:
标签: javascript html arrays function vue.js