当前位置:网站首页>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
边栏推荐
- [300 opencv routines] 241. Scale invariant feature transformation (SIFT)
- mysql查询条件字段值末尾有空格也能查到数据问题
- Brief analysis of advantages, disadvantages and development of SAP modules
- Ink wheel salon | Li Wenjie, Peking University: a graph database system for knowledge atlas application gstore
- Swoole Task任务使用
- 芯片行业常用英文术语最详细总结(图文快速掌握)
- 接口测试实战项目02:读懂接口测试文档,上手操练
- Vandermond convolution learning notes
- 进程与进程调度
- Understanding of cap
猜你喜欢

Code random notes_ Hash_ 1002 find common characters
![Leetcode:1997. the first day after visiting all rooms [jump DP]](/img/6e/52d5871a11d1b27e673112a8245b28.png)
Leetcode:1997. the first day after visiting all rooms [jump DP]

Redis sentinel mode

重新定义分析 - EventBridge 实时事件分析平台发布

分支和循环语句题目练习
![Deepening the concept of linear algebra [23] 01 - points coordinate points and vectors vectors](/img/9e/267ab60455e859afac3727eff32803.png)
Deepening the concept of linear algebra [23] 01 - points coordinate points and vectors vectors

Multithreading & high concurrency (the latest in the whole network: interview questions + map + Notes) the interviewer is calm

数组相关知识

Cross desktop web container evolution

Operator depth anatomy
随机推荐
Retinanet网络结构详解
The most detailed summary of common English terms in the chip industry (quick grasp of graphics and text)
Storage of deep planing data in memory
文件系统挂载
If asynchronous processing is implemented according to the framework
Matlab 绘制 - 点和向量:向量加减的方法和源码
Uniapp display rich text effect demo (organize)
0-1 knapsack problem
"C language" deep entry rounding & four functions
比亚迪半导体完成8亿元A+轮融资:30家知名投资机构入局,估值已达102亿元!
深度刨析数据在内存中的存储
福特SUV版“野马”正式下线,安全、舒适一个不落
浏览器视频帧操作方法 requestVideoFrameCallback() 简介
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
分支和循环语句题目练习
诺基亚宣布与博通合作开发5G芯片
Cross desktop web container evolution
Use of swarm task task
Swoole协程
Leetcode - find the median of two positively ordered arrays