欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

在统一应用程序中使用已计算的计算属性

最编程 2024-03-07 21:41:26
...

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()
	}
}

推荐阅读