Create custom property in JavaScript [closed]

2

I want to do the following, I use data types to create customizable properties, however I wanted to do as VueJS it has v-on among other properties and it was created using HTMLElement?

    
asked by anonymous 27.11.2018 / 16:15

1 answer

3

You can use v-bind to pass an object to the template that will register those attributes in HTML.

An example would look like this:

 new Vue({
   el: '#app',
   data: {
     customProps: {
       'data-foo': 100,
       'data-bar': 'algo'
     },
     message: 'Olá Vue.js!'
   }
 })
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script><divid="app">
  <p v-bind="customProps">{{ message }}</p>
</div>

And the resulting HTML is:

 <p data-foo="100" data-bar="algo">Olá Hello Vue.js!</p>
    
27.11.2018 / 16:23