<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<div v-for="(item, key) in items" v-show="key<num">
{{item}}
</div>
<span @click="showMore">{{txt}}</span>
</div>
<script src="https://unpkg.com/vue"></script>
<script>
var app = new Vue({
el: '#app',
data(){
return{
items: [
'a',
'b',
'c',
'd',
'e',
'f'
],
isShow: true,
txt: '显示全部',
num: 3
}
},
methods: {
showMore(){
console.log('1', this.isShow);
this.isShow = !this.isShow;
console.log('2', this.isShow);
this.num = this.isShow? 3: this.items.length;
this.txt = this.isShow? '显示全部':'收起'
}
}
})
</script>
</body>
</html>
点击加载更多
最新推荐文章于 2024-03-31 14:42:25 发布