简体   繁体   中英

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM