computed
是用于计算属性的选项。写法也是和methods同一级的,
用法:
1.在view中引入变量
<view class="">{{data}}</view>
2.在computed:{}方法里写计算逻辑在view中引入就可以了
computed:{
data (){
return 计算逻辑
}
}
方法举例
1.计算两个数的和
代码
运行结果
2.在子组件中写出 computed 返回 定义的数值 并 除以 2,并传给父组件
子组件 父组件
运行结果