vue / uniapp 小数点保留2位解决办法和异常处理vendor.js? [sm]:31 [Vue warn]: Error in render: “TypeError: Cannot read
一、上代码具体业务代码如下view class="price-box"><text>支付金额</text><text class="price">{{order.payableAmount|addZero }}</text></view>filters: {addZero:function(data){return data.toF
·
一、上代码
具体业务代码如下
view class="price-box"> <text>支付金额</text> <text class="price">{{order.payableAmount|addZero }}</text> </view>
filters: { addZero:function(data){ return data.toFixed(2) } },
如上操作,会出现报错信息如下
vendor.js? [sm]:31 [Vue warn]: Error in render: "TypeError: Cannot read property 'toFixed' of undefined"
更多详细报错
vendor.js? [sm]:31 [Vue warn]: Error in render: "TypeError: Cannot read property 'toFixed' of undefined"
(found in pages/money/Pay.vue)(env: Windows,mp,1.05.2201240; lib: 2.22.1)
ce @ vendor.js? [sm]:31
Dr.e.config.errorHandler @ vendor.js? [sm]:31
ml @ vendor.js? [sm]:31
pl @ vendor.js? [sm]:31
e._render @ vendor.js? [sm]:31
t @ vendor.js? [sm]:31
xt.get @ vendor.js? [sm]:31
xt @ vendor.js? [sm]:31
wr @ vendor.js? [sm]:31
Zt.$mount @ vendor.js? [sm]:31
attached @ vendor.js? [sm]:5
i.safeCallback @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
i.call @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
t @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
f @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
p.pretendAttached @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
fo @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
kt @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
(anonymous) @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
$t @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
(anonymous) @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
(anonymous) @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
q.emit @ WAServiceMainContext.js:2
emit @ WAServiceMainContext.js:2
(anonymous) @ WAServiceMainContext.js:2
q.emit @ WAServiceMainContext.js:2
emit @ WAServiceMainContext.js:2
(anonymous) @ WAServiceMainContext.js:2
(anonymous) @ WAServiceMainContext.js:2
c @ VM8 asdebug.js:1
u @ VM8 asdebug.js:1
(anonymous) @ VM8 asdebug.js:1
f @ VM8 asdebug.js:1
g @ VM8 asdebug.js:1
(anonymous) @ VM8 asdebug.js:1
_ws.onmessage @ VM8 asdebug.js:1
Show 6 more frames
vendor.js? [sm]:31 TypeError: Cannot read property 'toFixed' of undefined
at addZero (parkPay.js? [sm]:25)
at Proxy.n (parkPay.js? [sm]:17)
at u.e._render (vendor.js? [sm]:31)
at u.t (vendor.js? [sm]:31)
at xt.get (vendor.js? [sm]:31)
at new xt (vendor.js? [sm]:31)
at wr (vendor.js? [sm]:31)
at u.Zt.$mount (vendor.js? [sm]:31)
at ki.attached (vendor.js? [sm]:5)
at i.safeCallback (WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2)(env: Windows,mp,1.05.2201240; lib: 2.22.1)
Dr.e.config.errorHandler @ vendor.js? [sm]:31
ml @ vendor.js? [sm]:31
pl @ vendor.js? [sm]:31
e._render @ vendor.js? [sm]:31
t @ vendor.js? [sm]:31
xt.get @ vendor.js? [sm]:31
xt @ vendor.js? [sm]:31
wr @ vendor.js? [sm]:31
Zt.$mount @ vendor.js? [sm]:31
attached @ vendor.js? [sm]:5
i.safeCallback @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
i.call @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
t @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
f @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
p.pretendAttached @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
fo @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
kt @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
(anonymous) @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
$t @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
(anonymous) @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
(anonymous) @ WASubContext.js?t=wechat&s=1647707526833&v=2.22.1:2
q.emit @ WAServiceMainContext.js:2
emit @ WAServiceMainContext.js:2
(anonymous) @ WAServiceMainContext.js:2
q.emit @ WAServiceMainContext.js:2
emit @ WAServiceMainContext.js:2
(anonymous) @ WAServiceMainContext.js:2
(anonymous) @ WAServiceMainContext.js:2
c @ VM8 asdebug.js:1
u @ VM8 asdebug.js:1
(anonymous) @ VM8 asdebug.js:1
f @ VM8 asdebug.js:1
g @ VM8 asdebug.js:1
(anonymous) @ VM8 asdebug.js:1
_ws.onmessage @ VM8 asdebug.js:1
Show 5 more frames
vendor.js? [sm]:31 [Vue warn]: Error in render: "TypeError: Cannot read property 'toFixed' of undefined"
二、最终解决如下
特别补充
感谢这位朋友在评论区指正和补充
你好博主,我遇到一个情况,在转换的时候,不是因为空值,而是返回的是字符,用filters转换报错,需要对数据强转一下。toFixed只能针对Number类型才能使用,所以对于字符类型的要用parseFloat或者parseInt函数先转一下再调用
问题截图:
-
[Vue warn]: Error in render: "TypeError: data.toFixed is not a function"
-
(found in pages/time/index.vue)(env: Windows,mp,1.06.2209190; lib: 3.0.1)
更多推荐
已为社区贡献6条内容
所有评论(0)