[Vuejs]-Inserting a v-model into a vuejs element

2👍

You can make that model2 div a separate component o that it can be reused anywhere you want like this:

html

<div id="app">
   <input type="text" v-model="model1" />
   <reusable-comp></reusable-comp>
</div>

script

<script>

var reusableComp = {
    template: `
        <div id="model2">
          <div>ABCDEFG</div>
          <input type="text" />
        </div>
    `,
    data(){
        return{
           //reactive properties for this component 
        }
    }
}


new Vue({
        el: '#app',
        data: {'model1': 'value'},
        components:{
            reusableComp
        }
...
...
...
});
</script> 

You can also register that as a global component like this

Vue,.component('reusableComp',{ //...options })`

See docs for more on components

Leave a comment