搬运我在简书写的第一篇文章:再有人问你vue2 :v-for和v-if怎么优雅替代实现

27 阅读1分钟
<template>
 <div>
	<div v-for="(item,index) in userInputTips" :key="index" >
		{{ item}} 
	</div>
</div>
</template>
<script>
export default {
  name:'A',
  data () {
    return {
      tipsContent: [] 
    };
  },
  computed: {//通过计算属性过滤掉列表中不需要显示的项目
   userInputTips() {
	return this.tipsContent.filter(item => {
		return item.indexOf(this.textMsg) != -1
	})
    }
  }
};
</script>