Vue - 通过computed传值判断类型

通过返回函数,判断参数内容。

<view class="item" :style="{'background':cardBg(index)}" </view>

computed: {		
  cardBg() {
     return function(index) {
      switch (index) {
        case 0:
          return 'linear-gradient(90deg, #32AAFA 0%, #9FD8FF 100%)'
        case 1:
          return 'linear-gradient(90deg, #FF9F2C 0%, #FFC784 100%)'
        case 2:
          return 'linear-gradient(90deg, #23AB23 0%, #91F391 100%)'
        case 3:
          return 'linear-gradient(90deg, #7E23AB 0%, #D691F3 100%)'
			}
		}
	}
}
posted @ 2021-11-10 21:53  峻宇  阅读(524)  评论(0编辑  收藏  举报