Create custom property in Javascript

Asked

Viewed 50 times

2

Hello I want to do the following, I use data types to create customizable properties, but wanted to do as Vuejs it has v-model v-on among others this properties and created using Htmlelement?

  • @Did Sergio really understand the question? Not me. Matheus, do you want to do something in Vue, or do on your own similar to Vue?

  • @bfavaretto to me is clear the problem, an app that uses datatypes (attributes data-), hence my suggestion to use the v-bind. But I can clearly be wrong.

  • I think he wants to implement a reactive mechanism on his own, @Sergio. He says "but he wanted to do like Vuejs".

  • @bfavaretto ok, as I said, I may be wrong. Let’s see what Matheus says.

  • Matheus reads the above comments . If my answer is wrong do not accept it, so we can clarify and give an appropriate response.

  • Hello, the answer was with double meaning kkk, but finally I really wanted and do the same Vuejs on its own ( make a reactive component )

Show 1 more comment

1 answer

3

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

An example would be 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>

<div id="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>
  • 2

    It may not be what he’s asking, but I learned something new from his answer! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.