search

Home  >  Q&A  >  body text

javascript - Is there any way to make the components spliced ​​together by vue effective?

Element-ui is used in the project. For example, I want to dynamically generate N components.
<template>

<p class="search" ref="search" v-html="sHtml">

</p>

</template>

<script type="text/javascript">

export default {
    data() {
        return {
            sHtml: '',
        }
    },
    props: {
        con: {
            type: Array
        }
    },
    created() {
        this.con.map((v, i) => {
            this.sHtml += '<el-'+ v.type +' class="'+ v.style +'" placeholder="'+ v.placeholder +'" v-model="'+ v.name +'"></el-' + v.type +'>';
        });
    },
}

</script>

Is there any way to make the element plug-in render on the page?

阿神阿神2744 days ago779

reply all(5)I'll reply

  • 仅有的幸福

    仅有的幸福2017-06-26 10:56:13

    Can’t v-for directly where the component is referenced? .

    reply
    0
  • 黄舟

    黄舟2017-06-26 10:56:13

    Can’t you be more direct, like

        
     
     <p class="search" ref="search">
         <el-input  v-model="keyFrom.id" size="small" placeholder="请输入内容"></el-input>
     </p>

    reply
    0
  • 世界只因有你

    世界只因有你2017-06-26 10:56:13

    Compiling html is not supported now, but it will be possible in 1.0

    reply
    0
  • 習慣沉默

    習慣沉默2017-06-26 10:56:13

    Use v-for directly to render components through data [array]

    reply
    0
  • PHP中文网

    PHP中文网2017-06-26 10:56:13

    You can refer to: https://cn.vuejs.org/v2/guide...Dynamic components

    <component v-for="item in con" :is="item.name"></component>

    reply
    0
  • Cancelreply