computed的理解
computed里面的属性不能在data属性中出现,用来监控computed中自定义的变量
data() {
return {
url:"",
mode:"SD",
enableCamera:true,
position:"front",
beauty:0,
whiteness:0,
windowHeight:0,
context:null,
statusBarHeight:0,
popupType:"mode"
}
}
computed: {
// 计算属性的 getter
popupTitle() {
let o = {
mode: "画质",
beauty: "美颜",
whiteness: "美白"
}
return o[this.popupType]
}
}
computed合适多个变量或对象处理后返回一个结果值,其中一个值发生变化则computed监控的属性值就会发生变化
<view class="flex align-center justify-center border-bottom" style="height: 90rpx;">
<text class="font-md">{{popupTitle}}</text>
</view>
data() {
return {
url:"",
mode:"SD",
enableCamera:true,
position:"front",
beauty:0,
whiteness:0,
windowHeight:0,
context:null,
statusBarHeight:0,
popupType:"mode"
}
},
computed: {
popupTitle() {
let o = {
mode: "画质",
beauty: "美颜",
whiteness: "美白"
}
return o[this.popupType]
}
},
methods: {
openPopup(type) {
this.popupType = type
this.$refs.popup.open()
}
}
来源:oschina
链接:https://my.oschina.net/wwyywg/blog/4492506