4
A
回答
5
VanillaJS只意味着在純JS中沒有任何框架/包裝的情況下使用web組件。
您必須註冊您的自定義元素,衝出元素並自己處理數據綁定。
x-tag
和Polymer
都提供了一個方便和周到的Web組件封裝,大大減少了樣板代碼。
恕我直言Polymer
庫提供了最declerative方法(有關數據綁定,定義模板等)
這是怎麼看起來像X-標籤:
xtag.register('x-accordion', {
// extend existing elements
extends: 'div',
lifecycle:{
created: function(){
// fired once at the time a component
// is initially created or parsed
},
inserted: function(){
// fired each time a component
// is inserted into the DOM
},
removed: function(){
// fired each time an element
// is removed from DOM
},
attributeChanged: function(){
// fired when attributes are set
}
},
events: {
'click:delegate(x-toggler)': function(){
// activate a clicked toggler
}
},
accessors: {
'togglers': {
get: function(){
// return all toggler children
},
set: function(value){
// set the toggler children
}
}
},
methods: {
nextToggler: function(){
// activate the next toggler
},
previousToggler: function(){
// activate the previous toggler
}
}
});
這是怎麼回事看起來像聚合物:
<polymer-element name="polymer-accordion" extends="div" on-click="{{toggle}}">
<template>
<!-- shadow DOM here -->
</template>
<script>
Polymer('polymer-accordion' {
created: function() { ... },
ready: function() { ... },
attached: function() { ... },
domReady: function() { ... },
detached: function() { ... },
attributeChanged: function(attrName, oldVal, newVal) {
},
toggle : function() {....},
get togglers() {},
set togglers(value) {},
nextToggler : function() {},
previousToggler : function() {},
});
</script>
</polymer-element>
5
Web Components是瀏覽器中的本地實現。 聚合物是一種庫,它充當Web組件技術之上的一個非常薄的層。 X-Tag是另一個更薄的庫,因爲它僅依賴於四種Web組件技術之一。
我寫過一篇文章:http://pascalprecht.github.io/2014/07/21/polymer-vs-x-tag-here-is-the-difference/
相關問題
- 1. 比較香草JS和JQuery
- 2. 如何使用香草js從聚合物元素更新數據(dom)?
- 3. 在香草中比較兩個包含對象的數組JS
- 4. 「這個」參考ecmascript相比,香草JS
- 5. Modernizr.mq在香草JS
- 6. 炸彈香草JS
- 7. jQuery來香草JS
- 8. 不能與COUNT混合聚合和非聚合比較
- 9. 更改背景顏色與香草JS
- 10. 聽取與香草JS jQuery事件
- 11. 如何創建與jQuery(或香草JS)
- 12. toogle數據集trenary與香草js
- 13. 香草JS插件模板
- 14. 香草js刪除id框
- 15. 香草JS Fizzbuzz不工作
- 16. Web組件(香草,無聚合物):如何加載<template>的內容?
- 17. Scala - 聚合與性能的比較leftLeft
- 18. 編譯和渲染與香草的車把模板JS
- 19. 與節點,快遞和香草JS的AJAX調用
- 20. 獲取滾動位置和方向與香草JS
- 21. react js和Angular js之間的性能比較?
- 22. 操縱和香草的JavaScript
- 23. for循環後的addEventListener類;香草JS
- 24. 轉成jQuery的香草JS - 後H1
- 25. 聚合物與Angularjs
- 26. 將香草物體轉換爲類?
- 27. Django聚合和註解行爲比較
- 28. 什麼是普通香草JavaBeans和普通香草Java類?
- 29. 聚合物元素中this和this.root之間的區別
- 30. matiasgagliano/guillotine項目作爲香草JS
您是否試過Google? –
@Java_User是的,我已經嘗試過,但沒有得到任何明確的比較。感謝您的回覆。 –