vue template 使用
目录
template
的作用是模板占位符,可帮助我们包裹元素,但在循环过程当中,template不会被渲染到页面上
使用场景
若不想额外增加一个div,可以使用template来实现
1 2 3 4
<template v-for="(item, index) in list" :key="item.id"> <div>{{item.text}}--{{index}}</div> <span>{{item.text}}</span> </template>
实战
|
|
备注:使用一个template
包裹两个div
,而不能直接用两个template
且在其标签里用v-if
、v-else