Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Petite-vue Init attribute in HTML script tag

I recently saw this Vue.js snippet by Evan You on Twitter, and I don't understand what the init attribute in the script tag does. I could not find anything about this on MDN or similar sites.

The defer attribute is clear to me.

<script src="https://unpkg.com/petite-vue" defer init></script>

<!-- anywhere on the page -->
<div v-scope="{ count: 0 }">
  {{ count }}
  <button @click="count++">inc</button>
</div>
like image 524
Janis Jansen Avatar asked Dec 09 '22 23:12

Janis Jansen


1 Answers

It's explained in the repo Readme file in the Usage section :

The init attribute tells petite-vue to automatically query and initialize all elements that have v-scope on the page.

and according to this code snippet it's a custom attribute and it's used to mount the app if the script tag is present :

let s
if ((s = document.currentScript) && s.hasAttribute('init')) {
  createApp().mount()
}
like image 200
Boussadjra Brahim Avatar answered Dec 27 '22 11:12

Boussadjra Brahim