使用方法
使用script标签引入
通过script标签使用在线版本
<script src="https://unpkg.com/art-template@4.13.2/lib/template-web.js"></script>
在webpack中使用
语法
基本语法
-
使用script标签定义模板。type属性需修改为text/html,需要定义id属性
-
在js中,使用template方法使用模板。需要传入的参数为:模板id,数据对象
-
通过 { {对象属性}} 使用对象属性
<script id="tp",type="text/html"> // 通过 { {对象属性}} 使用对象属性 <li>{ {name}} { {age}}<li> </script> <script> template('tp',{ name:'skc', age:'21' }) </script>
-
{ {@对象属性}} 的@表示不对html内容进行转义处理
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8eoRYubu-1614920664799)(4A7752E81059472CAAC2277995