vue將div更改成input文本輸入框


<template>
    <div class="DivContentEdit">
      <div :class="canEdit ? ['div-text','edit-div'] : ['edit-div']"
           v-html="innerText"
           :contenteditable="canEdit"
           @focus="isLocked = true"
           @blur="isLocked = false"
           @input="changeText">
      </div>
    </div>
</template>

<script>
    export default {
      props: {
        value: {
          type: String,
          default: ''
        },
        canEdit: {
          type: Boolean,
          default: true
        }
      },
      data(){
        return {
          innerText: this.value,
          isLocked: false
        }
      },
      watch: {
        'value'(){
          if (!this.isLocked || !this.innerText) {
            this.innerText = this.value;
          }
        }
      },
      methods: {
        changeText(){
          this.$emit('input', this.$el.innerText);
        }
      }
    };
</script>

<style scoped>
  .div-text {
// 這個可以去掉樣式問題 -webkit-user-modify: read-write-plaintext-only; } div span p :focus{ outline: none; } </style>

  

vue將div更改成input文本輸入框

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM