【发布时间】:2018-03-10 16:03:49
【问题描述】:
现在我很沮丧:(这是我第一次尝试使用 vue.js,这是继 jQuery 之后我来到这个星球以来学习的第二个 JS 框架。我有以下 HTML:
var main = new Vue({
el: ".main-content",
data: {
heading: "First Vue Page",
usdamount: 0,
currencies: [{
label: "GBP",
rate: 0.7214,
value: 0
},
{
label: "EUR",
rate: 0.80829,
value: 0
},
{
label: "CAD",
rate: 1.2948,
value: 0
}
]
},
computed: {
updateCurrencies: function() {
console.log(this.usdamount);
var usd = parseFloat(this.usdamount);
for (var i = this.currencies.length - 1; i >= 0; i--) {
this.currencies[i].value = this.currencies[i].rate * usd;
}
}
}
});
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<section class="main-content">
<h1>{{ heading }}</h1>
<input type="number" v-on:change="updateCurrencies" v-model="usdamount">
<p class="cur-value" v-for="cur in currencies">
<strong>{{ cur.label }}</strong>: {{ cur.value }}
</p>
</section>
当我加载页面时,一切正常,我在控制台上记录了一个零。如果我尝试更改我得到的输入:
TypeError: e is undefined
Stack trace:
we@https://cdn.jsdelivr.net/npm/vue:6:26571
X@https://cdn.jsdelivr.net/npm/vue:6:7441
...
我去了抱怨的部分,却更加迷失了。就是这个函数:
function we(t,e,n,r){(r||si).removeEventListener(t,e._withTask||e,n)}
即使经过多次尝试更改和隔离问题,我也不知道是什么导致了错误。
【问题讨论】:
-
你在 Chrome 中安装了 Vue 开发者扩展吗?这通常有助于检查 Vue 端是否一切正常。
-
我远非 vuejs 专家,但根据我在文档上阅读的内容,
computed属性是否不适用于computed properties,我认为您需要移动@987654327 @ 到你的 vue 实例的methods属性。
标签: javascript vue.js vuejs2