Ali EXE
Ali EXE

Reputation: 1361

How to select the vue js el using CSS attribute selector?

I have this HTML:

<div data-identifier='app'>
   ...
</div>

And I have this Vue js code:

      var app = new Vue({
            el: '[data-identifier]',
            data: {
                
            },
            methods: {

            }
        });

But it seems that Vue does not understand [data-identifier] CSS selector.

How can I use attribute CSS selector with Vue js?

Upvotes: 0

Views: 226

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

It should work as shown below:

  var app = new Vue({
            el: '[data-identifier]',
            data: {
              msg:"hello" 
            },
            methods: {

            }
        });
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div data-identifier='app'>
   {{msg}}
</div>

Upvotes: 1

Related Questions