Skip to content

Commit

Permalink
若大于4位小数则仅展示4位小数并支持hover展示完整,否则直接展示完整
Browse files Browse the repository at this point in the history
  • Loading branch information
realgeoffrey committed Aug 7, 2024
1 parent 17592d3 commit 5e36f19
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions 网站前端/Vue.js学习笔记/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4325,6 +4325,55 @@ Vue.use(MyPlugin, { /* 向MyPlugin传入的参数 */ })
4. `<el-option>`能够匹配 空字符串、`undefined``null`,并且多个相同的value值匹配后展示最后一个项的label值,注意传参为空时出现的问题
>[CodePen demo](https://codepen.io/realgeoffrey/pen/MWMpxNW)
5. <details>
<summary>若大于4位小数则仅展示4位小数并支持hover展示完整,否则直接展示完整</summary>
```vue
<template>
<el-tooltip
v-if="showTooltip(num)"
:content="String(num)"
:placement="placement"
>
<span>{{ showToDecimalPlaces4(num) }}</span>
</el-tooltip>
<span v-else>{{ num }}</span>
</template>
<script>
import Decimal from "decimal.js";
export default {
props: {
num: {
type: [Number, String, null],
default: "",
},
placement: {
type: String,
default: "bottom",
},
},
methods: {
showToDecimalPlaces4(number) {
if (!number) {
return "";
}
try {
return Decimal(number).toDecimalPlaces(4).toString();
} catch {
return String(number);
}
},
showTooltip(number) {
return number && this.showToDecimalPlaces4(number) !== String(number);
},
},
};
</script>
```
</details>
### jQuery与Vue.js对比
1. 做的事情
Expand Down

0 comments on commit 5e36f19

Please sign in to comment.