props: ['item'],
computed: {
coinPrice () {
return this.item.currentPrice.toFixed(2)
}
}
第一次加载报的未定义异常,很奇怪?我查了百度说是数据请求的结果是异步执行的,所以第一次加载报未定义异常,那么该怎么解决呢?
props: ['item'],
computed: {
coinPrice () {
return this.item.currentPrice.toFixed(2)
}
}
第一次加载报的未定义异常,很奇怪?我查了百度说是数据请求的结果是异步执行的,所以第一次加载报未定义异常,那么该怎么解决呢?
computed: {
coinPrice () {
return typeof this.item.currentPrice === 'number' ? this.item.currentPrice.toFixed(2) :
this.item.currentPrice
}
}
10 回答11.3k 阅读
5 回答4.9k 阅读✓ 已解决
4 回答3.2k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
2 回答4.8k 阅读✓ 已解决
4 回答4.4k 阅读✓ 已解决
4 回答1.9k 阅读✓ 已解决
解决了,在data里面定义个属性来接收props里面的值,然后用data里面的属性来计算。perfect
props: ['item'],
computed: {
}
data(){
return{
}
}