import Vue from 'vue';import {Component} from 'vue-property-decorator';@Componentexport default class NumberPad extends Vue {output = '0'; // 输出的数字为字符串类型outputChange(event: MouseEvent) {// vue会读取div的内容const input = event.target.textContent;if (this.output.length === 16) {return;}if (this.output === '0') {if ('0123456789'.indexOf(input) >= 0) {this.output = input;} else {this.output += input;}return}if (this.output.indexOf('.') >= 0 && input === '.') {return;}this.output += input;}deleteLast(){if(this.output.length === 1) {this.output = '0'} else {this.output = this.output.slice(0,-1) // -1表示最后一个元素}}clear(){this.output = '0'}}</script>
如果webstorm提示你某个值可能为null,可强制指定类型
// 1. 用 asevent.target as HTMLButtonElement// 2. 用感叹号event.target!
