Template html and template string in web components

我是研究僧i 提交于 2019-12-08 01:03:54

问题


Is it better to use html template (and then html import) to create web components or to use template string? What are pros and cons of these methods?


回答1:


Using html template files is better for reuse: the same file can be used in different web components. Also they are better displayed in most IDEs as they are recognized as full HTML code.

Using template strings is faster (inline). They don't rely on HTML Imports which is not adopted by every browser vendors. Also you can use template literals to insert directly value of JavaScript variables in the DOM.

Actually there's no much diffrences because there's a workaround for every differences list above (i.e. you can reuse template strings if you save them as text file, or you can load html templates withour HTML imports).



来源:https://stackoverflow.com/questions/41637056/template-html-and-template-string-in-web-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!