export default { data() { return { counter: 0, loading: false, textarea: '', text: '', textMaxLength: 29, isDisable: false, }; }, methods:{ onDisabledTextarea(){ // 5min后禁用文本域 setTimeout(() => { this.isDisable = true; }, 1000 * 300); }, copyToClipboard(elemRef) { let target; let succeed = false; if(this.$refs[elemRef]){ target = this.$refs[elemRef]; // 选择内容 let currentFocus = document.activeElement; target.focus(); target.setSelectionRange(0, target.value.length); // 复制内容 try { succeed = document.execCommand("copy"); } catch (e) { succeed = false; } // 恢复焦点 if (currentFocus && typeof currentFocus.focus === "function") { currentFocus.focus(); } } return succeed; }, /* descInput(){ var txtVal = this.text.length; this.counter = txtVal; },*/ onKeyup(){ let val = this.text.split(" "); var count=0 for(var i=1;i<this.text.length;i++){ if(text.charAt(i)==' ') { this.count++ } } } }, watch:{ }, computed: { }, directives: { sliceString: { update(el, binding) { if (el.value.length >= binding.value) { el.value = el.value.slice(0, binding.value) } } } }, }
主要是onKeyup这个函数的编写和调用
求大神帮忙看一下