VUE取消input回車換行的問題

<el-form-item>
    <el-input 
      placeholder="請輸入關(guān)鍵詞后回車確認(rèn)"
      type="textarea" 
      maxlength="10" 
      v-model="keyword" 
      @keydown.native="pushKeyword($event)"
      :rows="4">
</el-input>
<div class="keyword">
    <el-tag 
      v-for="(tag,index) in feedsForm.keyword"
      :key="tag"
      closable
      type="info"
      @close="handleClose(index)">
      {{tag}}
    </el-tag>

    <span class="length">
      <span class="num">{{feedsForm.keyword.length}}</span>/ 10
    </span>
</div>
</el-form-item>
data() {
    return {
    feedsForm:{},
      keyword: "",
},

methods:{
 // 獲取關(guān)鍵詞
    pushKeyword(event) {
      if (event.keyCode === 13) {
        event.preventDefault(); // 阻止瀏覽器默認(rèn)換行操作
        if (this.keyword && this.feedsForm.keyword.length < 10) {
          this.feedsForm.keyword.push(this.keyword);
        }
        this.keyword = "";
        return false;
      }
    },
    // 關(guān)鍵詞關(guān)閉事件
    handleClose(index) {
      this.feedsForm.keyword.splice(index, 1);
      // debugger;
      console.log(index);
    }
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容