uni-app 计算属性 computed

时间:2020-01-12 20:18:21   收藏:0   阅读:3351

功能:=》大于1000用kg表示 小于1000,用g表示

    计算属性  计算属性必须是有一个返回值的哦  
    在html写被计算的值
    在computed中去直接调用哈

        <view>
            <text>{{jisuweight}}</text>
        </view>
        
        data() {
            return {
                weight:1110,
            }
        },
        computed:{
            jisuweight(){
                return this.weight>1000 ? (this.weight/1000)+"kg" : this.weight;
            }
        },
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!