我最近看到了这个Vue.js
Evan You 在 Twitter 上的片段,我不明白 init
是什么script 标签中的属性确实如此。我在 MDN 或类似网站上找不到任何关于此的内容。defer
属性对我来说很清楚。
<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>
最佳答案
它在 Usage 的 repo 自述文件中进行了解释。部分 :
The
init
attribute tellspetite-vue
to automatically query and initialize all elements that havev-scope
on the page.
并据此code snippet它是一个自定义属性,如果存在 script 标签,它用于挂载应用程序:
let s
if ((s = document.currentScript) && s.hasAttribute('init')) {
createApp().mount()
}
关于javascript - HTML脚本标签中的Petite-vue Init属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68238484/