<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<div class="hello">
<div v-for='item in showList'>{{item}}</div>
<div @click="showAll = !showAll" class="show-more">{{word}}</div>
</div>
</body>
</html>
<script type="text/javascript">
new Vue({
el: '.hello',
data(){
return{
toLearnList:[
'html','css','javascript','java','php'
],
showAll:false,
}
},
computed:{
showList:function(){
if(this.showAll == false){
var showList = [];
if(this.toLearnList.length > 3){
for(var i=0;i<3;i++){
showList.push(this.toLearnList[i])
}
}else{
showList = this.toLearnList
}
return showList;
}else{
return this.toLearnList;
}
},
word:function(){
if(this.showAll == false){
return '点击展开'
}else{
return '点击收起'
}
}
}
})
</script>