Demo 在线地址:
https://sx00xs.github.io/test/20/index.html
---------------------------------------------------------------
ide: vscode
文件格式:.vue
解析:(待补)
<template> <div id="app"> <input type="text" class="f-text" v-model="number1" @keyup="handleNum1"> <strong>+</strong> <input type="text" class="f-text" v-model="number2" @keyup="handleNum2"> <strong>=</strong><span>{{sum}}</span> <input type="button" value="求和" @click="handleSum"> </div> </template> <script> export default { data:function(){ return{ number1:'', number2:'', sum:'?' } }, methods:{ handleNum1(){ this.number1=this.number1.replace(/[^d]/,''); }, handleNum2(){ this.number2=this.number2.replace(/[^d]/,''); }, handleSum(){ (this.number1=='' || this.number2=='') ? alert('请输入数字!') : this.sum=parseInt(this.number1) + parseInt(this.number2); } } } </script>