简体   繁体   English

VueJS:如何将emoji表情组件动态嵌入到contentEditable div中

[英]VueJS: How to embed the emoji component dynamically in contentEditable div

How to embed the emoji component dynamically in contentEditable div while typing some text inside the div. 如何在div中键入一些文本的同时将emoji表情组件动态嵌入到contentEditable div中。

Here is the extract of my code: 这是我的代码的摘录:

 <picker set="emojione" @select="addEmoji" /> <div> {{ inputBoxValue }} </div> <script> export default { name: 'Some', components: { picker: Picker, emoji: Emoji, }, data() { return { inputBoxValue: '', }; }, methods: { addEmoji() { this.inputBoxValue = ' < emoji emoji = "{ id: " heart_eyes ", skin: 2 }" set = "emojione" size = "16" tooltip = "true" / > '; } } }; <script> 

Your thinking about the problem wrong here, instead of adding the components via a string into the dom you'll need to start using v-for and components. 您在这里对问题的想法是错误的,而不是通过字符串将组件添加到dom中,而需要开始使用v-for和component。 For instance if we create the following component: 例如,如果我们创建以下组件:

<div>
    {{emojiText}}
</div>

<script>
    export default {
       props: ['id', 'set', 'size', 'tooltip'],
        name: 'InnerEmojiHolder',
        data() {
            return {
                emojiText: '',
            };
        },
        methods: {

        },
        ready(){
         // put logic to build emoji here using props
        }
    }; 
<script>

This can then be used inside of your existing component like so: 然后可以在现有组件内部使用它,如下所示:

<picker set="emojione" @select="addEmoji" />
<div>
  <template :for="emoji, index in currentInput">
    <innerEmojiHolder :id="index" :set="emoji.set" :tooltip="emoji.tooltip" :size="emoji.size" : ></innerEmojiHolder>
  </template>
</div>

<script>
    export default {
        name: 'Some',
        components: {
            picker: Picker,
            emoji: Emoji,
            innerEmojiHolder: innerEmojiHolder,
        },
        data() {
            return {
                currentInput: []
            };
        },
        methods: {
            addEmoji() {
             // Push our emoji variables into currentInput
            }
        }
    }; 

This allows us to print out all of the emoji's using a for and will use the data from the parent inside of the child. 这使我们可以使用for打印所有表情符号,并将使用子代内部的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM