uniapp 组件过滤器 computed

uniapp yekong 638℃

vue使用组件计算来代替过滤器。

使用组件

<getType :type="item.houseType" :houseType="houseType"></getType>

组件代码

<template>
	<view>
		{{getType}}
	</view>
</template>

<script>
	import {
		getRentalHouse
	} from '@/config/api.js'
	export default {
		components: {},
		data() {
			return {
				rentalId: 0,
			}
		},
		props: {
			houseType: {
				type: Array,
				default () {
					return []
				}
			},
			type: {
				type: Number | String,
				default () {
					return 0
				}
			},
		},
		computed: {
			getType: function() {
				var that = this;
				var name = ""
				that.houseType.forEach((typeData) => {
					if (this.type == typeData.dictValue) {
						name = typeData.dictLabel
					}
				});
				return name
			}
		},
		methods: {

		}
	}
</script>

喜欢 (2)