Vue 2 contentEditable with v-model

12 浏览
0 Comments

Vue 2 contentEditable with v-model

我正在尝试制作一个类似Medium的文本编辑器。我使用contenteditable段落标签,并将每个项目存储在数组中,然后使用v-for渲染每个项目。然而,我在使用v-model绑定文本和数组时遇到了问题。似乎v-model和contenteditable属性存在冲突。以下是我的代码:

     
     

在我的脚本中:

export default { 
   data() {
      return {
         content: [{ value: ''}]
      }
   },
   methods: {
      stylize(style) {
         document.execCommand(style, false, null);
      },
      remove_content(index) {
         if(this.content.length > 1 && this.content[index].value.length == 0) {
            this.content.splice(index, 1);
         }
      }
   }
}

我在网上没有找到任何答案。

0