简单利用vue实现多层嵌套列表渲染

效果图如下

vue.js多层嵌套列表渲染

  1. html部分
<ul>
   <template v-for="(item, index) in wjList">
   	<li class="voteList-li" v-for="newItem in item" v-on:click="addClassFun(index)">
   		<a v-bind:class='{voteListOn:index==indexFun}' href="###">
   			<img :src='newItem.src' alt="" />
   			<ul class="voteList-text">
   				<li><i class="i-one"></i>{{newItem.title}}</li>
   				<li><i class="i-two"></i>{{newItem.time}}</li>
   				<li><i class="i-three"></i>{{newItem.remarks}}</li>
   			</ul>
   		</a>
   	</li>
   </template>
</ul>
  1. js部分
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
	<script>
		var app = new Vue({
			el: '#app',
			data: {
				//问卷列表
				indexFun: "0",
				wjList: [{
					item: {
						src: "../images/vote_open02.png",
						title: "对众智传学用户体验度的调查",
						time: "发布时间:2018-12-01 15:36",
						remarks: "备注:已有45名同学参与了答卷"
					}
				}, {
					item: {
						src: "../images/vote_open02.png",
						title: "对众智传学用户体验度的调查",
						time: "发布时间:2018-12-01 15:36",
						remarks: "备注:已有45名同学参与了答卷"
					}
				}, {
					item: {
						src: "../images/vote_open02.png",
						title: "对众智传学用户体验度的调查",
						time: "发布时间:2018-12-01 15:36",
						remarks: "备注:已有45名同学参与了答卷"
					}
				}, {
					item: {
						src: "../images/vote_open02.png",
						title: "对众智传学用户体验度的调查",
						time: "发布时间:2018-12-01 15:36",
						remarks: "备注:已有45名同学参与了答卷"
					}
				}]
			},
			methods: {
				//左侧列表点击添加class
				addClassFun: function (id) {
					this.indexFun = id;
				},
			}
		})
	</script>

这样一个简单的多层嵌套列表就实现了。

相关文章:

  • 2021-03-31
  • 2021-11-30
  • 2021-06-29
  • 2018-01-04
  • 2021-11-01
  • 2021-10-05
  • 2019-11-17
  • 2019-10-30
猜你喜欢
  • 2021-09-25
  • 2021-11-02
  • 2021-12-09
  • 2021-12-12
  • 2020-04-21
  • 2021-11-14
  • 2017-11-24
相关资源
相似解决方案