当前位置:网站首页>JS global function method module exports exports
JS global function method module exports exports
2022-07-28 01:13:00 【linzhiji】
Definition butil.js
/**
* @ Get string byte length
* @param {String} str
* @returns
*/
function getStrLen (str) {
let len = 0;
for (let i = 0; i < str.length; i++) {
let currLen = str.charCodeAt(i);
if (currLen >= 0 && currLen <= 128) {
len += 1;
} else {
len += 2;
}
}
return len;
}
/**
* @ Intercepts a string of a specified length , The excess part displays the specified characters
* @param {*} name
* @param {number} [len=8]
* @param {string} [endStr="..."]
* @returns
*/
export function cutOffStr (name, len = 8, endStr = "...") {
// Less than or equal to the specified length
if (getStrLen(name) <= len) return name;
// Exceeds the specified length
let formatName = '';
let strLen = 0;
for (let i = 0; i < name.length; i++) {
strLen += getStrLen(name[i]);
if (strLen <= len) {
formatName += name[i];
} else {
break;
}
}
return formatName + endStr;
}
stay vue in
# quote
import {cutOffStr} from '@/utils/butil.js'
# Use... In code
cutOffStr(srcStr)If in vue Direct use in
<u-th>{
{cutOffStr(item.user_nick, 10)}}</u-th>
Will report a mistake
Error in render: "TypeError: _vm.cutOffStr is not a function"
Need to be in methon Make it clear again in
methods: {
cutOffStr,
}JS Module export and import export and module.export The difference between - Simple books
vue Cannot be directly in html Use in import Of js Method question ( Personal notes ) - Simple books
边栏推荐
- CAP的理解
- 共创文旅新篇章|新起典与国华文旅签订战略合作协议
- Recommended system model (III): fine scheduling model [LR, gbdt, wide & deep, DCN, DIN, Dien, MMOE, ple]
- SAP各模块优缺点和发展简析
- Unknown database ‘xxxxx‘
- 立即报名 | 云原生技术交流 Meetup 广州站已开启,8 月 6 号与你相遇!
- Redis cache penetration breakdown and avalanche
- c# 反射之Type使用
- Ink wheel salon | Li Wenjie, Peking University: a graph database system for knowledge atlas application gstore
- File system mount
猜你喜欢

File system mount

Code random notes_ Hash_ 1002 find common characters

Use of postman

福特SUV版“野马”正式下线,安全、舒适一个不落

Resolved Unicode decodeerror: 'UTF-8' codec can't decode byte 0xa1 in position 0: invalid start byte

The most detailed summary of common English terms in the chip industry (quick grasp of graphics and text)

共创文旅新篇章|新起典与国华文旅签订战略合作协议

Six relationships of UML class diagram, the best way to learn and understand

DEMO:测试接口短时间内接收重复数据创建单据

The cooperation between starfish OS and metabell is just the beginning
随机推荐
Oracle错误: ORA-01722 无效数字
110. SAP UI5 FileUploader 控件深入介绍 - 为什么需要一个隐藏的 iframe
"C language" deep entry rounding & four functions
总投资近16亿元!乾照光电VCSEL、高端LED芯片项目正式开工
Swoole Task任务使用
函数相关知识
Postman 的使用
Deepening the concept of linear algebra [23] 01 - points coordinate points and vectors vectors
[introduction to C language] zzulioj 1026-1030
[BuildRelease Management]Parabuild
分支和循环语句题目练习
推荐系统-模型(三):精排模型【LR、GBDT、Wide&Deep、DCN、DIN、DIEN、MMOE、PLE】
Uniapp display rich text effect demo (organize)
推荐系统-离线召回:u2tag2i、icf
【C语言入门】ZZULIOJ 1026-1030
Jmeter在性能测试中的应用实践样例
Programmer growth Chapter 30: do you really understand feedback?
网络安全漏洞分析与漏洞复现
Swoole内存-table详解
Byte flybook Human Resource Kit three sides