Skip to content
On this page
🎨 作者:Jacinda 📔 阅读量:

April

4月18日

Uniapp - 动态 Class 传参问题

  • ❓ 问题描述

原先的写法如下,因为需要根据条件动态改变 class,所以用了 计算属性 来写,而没有采用嵌入式。

但是运行的时候报了一个错误:

WARNING

Errors compiling template: :class不支持 getCouponCardClass(item) 语法

html
<block v-for="(item,index) in initCouponList" :key="index">
    <view class="coupon_card" :class="getCouponCardClass(item)">
        ...
    </view>
</block>
  • 💡 解决

Uniapp 中,动态改变 Class,需要加 “[ ]”

html
<view class="coupon_card" :class="[getCouponCardClass(item)]">

5月14日

时间戳转换

  • ❓ 问题描述

遇到了偷懒的后端,传回原始时间戳 17xxxxxxx

  • 💡 解决
javascript
function getTransferDate(n) {
	let now = new Date(n),
	y = now.getFullYear(),
	m = now.getMonth() + 1,
	d = now.getDate();
	return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
}