Web组件中的模板html和模板字符串 [英] Template html and template string in web components

查看:244
本文介绍了Web组件中的模板html和模板字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用html模板(然后html导入)创建Web组件或使用模板字符串是否更好?这些方法的优缺点是什么?

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?

推荐答案

使用 html模板文件更好地重用:同一文件可用于不同的Web组件.而且,由于它们被认为是完整的HTML代码,因此在大多数IDE中都可以更好地显示它们.

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.

使用模板字符串更快(内联).他们不依赖于并非所有浏览器供应商都采用的HTML导入.您也可以使用模板文字直接插入值DOM中的JavaScript变量.

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.

实际上并没有太大的区别,因为上面的每个差异列表都有一个解决方法(即,如果将模板字符串保存为文本文件,则可以重复使用模板字符串,或者可以将HTML导入加载到HTML模板中).

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).

这篇关于Web组件中的模板html和模板字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆