两者可谓是一脉相承却略有不同。
与标准Vue 相比,petite-vue 具备vue相同的模板语法和响应式模型,从用途上来看,二者的差别在于标准Vue 可以用于复杂的单页面应用,往往页面里是没有内容的,需要初始化Vue 后异步加载,而petite-vue 则专门针对在已经服务器框架渲染好的现有HTML 页面上的少量交互进行了优化。我们来看看petite-vue的示例代码:
<!DOCTYPE html>使用 v-scope 在页面上标记应被 petite-vue 控制的区域。
<html>
<head>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/petite-vue.js" defer init></script>
</head>
<body>
<!-- anywhere on the page -->
<div v-scope="{ count: 0 }">
{{ count }}
<button @click="count++">inc</button>
</div>
</body>
</html>
defer 属性使脚本在 HTML 内容经过解析后执行。init 属性使 petite-vue 自动 query 并初始化页面上被 v-scope 标记的所有元素,其实就是直接自动执行了PetiteVue.createApp().mount()方法,如果去掉init,就要手动编写一个script
<script>PetiteVue.createApp().mount()</script>
petite-vue 具备以下特性:
大小仅为约 5.8kb
Vue 兼容的模板语法
基于 DOM (mutates in place)
由 @vue/reactivity 驱动
参考文章https://zhuanlan.zhihu.com/p/387543297
网友回复