基本等同与vue,把代码跑一下,看看就明白了。
其中,
v-hidden 貌似不管是 true or false 都有显示
v-show 才切换。
和vue 一样,数组循环中要加key绑定,只不过如果不加的话会有警告。
<view v-for="(item, index) in students" :key="index" >
<view class="persons">{{index}} - {{item.name}}</view>
</view>
测试源码
<template>
<view class="content">
<image class="logo" src="../../static/logo.png"></image>
<view>
<text class="title">{{title}}</text>
</view>
<h5>-------数据绑定展示 基本数据-------</h5>
{{name}}
<h5>-------数据绑定展示 数组-------</h5>
<view v-for="(item, index) in students" :key="index" >
<view class="persons">{{index}} - {{item.name}}</view>
</view>
<view v-if="show_if">
这里是条件展示的内容....是否显示if {{show_if}}
</view>
<view v-show="show_hidden">
这里是条件展示的内容....是否隐藏 {{show_hidden}}
</view>
</view>
</template>
<script>
var _self;
export default {
data() {
return {
title: 'Hello....',
name: 'hcoder',
students: [{
name: "张三",
age: 18
},
{
name: "李四",
age: 20
},
{
name: "王二",
age: 60
}
],
show_if: false,
show_hidden: true,
count: 0,
}
},
onLoad() {
_self = this;
setInterval(function() {
_self.count++;
console.log('第几次='+_self.count);
if (_self.count > 10) {
_self.show_if = true;
_self.show_hidden=false
}
if (_self.count > 20) {
_self.show_if = false;
_self.show_hidden=true;
_self.count = 0;
}
}, 2000);
},
methods: {
}
}
</script>
<style>
.content {
text-align: center;
height: 400upx;
}
.logo {
height: 200upx;
width: 200upx;
margin-top: 20upx;
}
.title {
font-size: 36upx;
color: #8f8f94;
}
h5 {
margin-top: 10px;
}
</style>
效果
来源:oschina
链接:https://my.oschina.net/qingqingdego/blog/3161211