可以理解为是对data中的数据提供了一种加工或者过滤功能,通过computed来定义计算属性
<template>
<view class="content">
<view>{{cnMoney}}</view>
<view v-for="(item,index) in filterList" :key="item.id">{{item.id}}--{{item.text}}--{{index}}</view>
</view>
</template>
<script>
export default {
//1 data 定义数据
data(){
return{
//存放数据
list:[
{
id:0,
text:"🍎"
},
{
id:1,
text:"🍌"
},
{
id:2,
text:"🍒"
},
{
id:3,
text:"🍊"
},
],
money:10000
}
},
//2 计算属性
computed:{
//把cnMoney看作是在data中的普通数据一样使用就可
cnMoney(){
//¥ 1000
return "¥" + this.money;
},
filterList(){
//显示id<=1
return this.list.filter(v=>v.id<=1);
}
}
}
</script>
运行结果