私はvue.jsアプリケーションを作成しようとしています。私は私の '結果'メソッドに問題があります - 入力に渡された数値を平方根にする必要があります。それを機能させるために私は何ができますか?vue.jsの平方根
HTML:
<div id="app" class="container">
<button class="root" @click="filter()">Root Extraction</button>
<template v-if="rootObject.squareRoot">
<div class="rootBox">
<h1>Type a random number to square root it!</h1>
<input id="number" type="number" min="0"/>
<button id="button" @click="results()" type="button">Count it</button>
<h1 id="result"></h1>
</div>
</template>
</div>
のJS:だから、あなたの質問に簡単な答えは、あなたが "document.getByを..." を使用してはならないことvuejsである
var result = document.getElementById("result");
new Vue({
el: '#app',
data: {
rootObject: {
squareRoot: false,
}
},
methods: {
results: function() {
result.innerHTML = "Square rooted number is: " + Math.sqrt(document.getElementById("number").value);
},
filter: function() {
this.rootObject.squareRoot = !this.rootObject.squareRoot;
}
}
})
ありがとうございます。 HTMLの誤植は偶然だった。 – kabugh