当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
C language programming | single dog topic explanation
4月全球智能手机出货同比下滑41%,华为首次超三星成全球第一
Resolved Unicode decodeerror: 'UTF-8' codec can't decode byte 0xa1 in position 0: invalid start byte
Examples of application of JMeter in performance testing
Hierarchy of file system
Swoole协程
Function related knowledge
福特SUV版“野马”正式下线,安全、舒适一个不落
Redis cache penetration breakdown and avalanche
Programmer growth Chapter 30: do you really understand feedback?
Jmeter在性能测试中的应用实践样例
Go language variable
Redis sentinel mode
Recommended system model (III): fine scheduling model [LR, gbdt, wide & deep, DCN, DIN, Dien, MMOE, ple]
Unknown database ‘xxxxx‘
[300 opencv routines] 241. Scale invariant feature transformation (SIFT)
数组相关知识
Postman 的使用
Oracle grouping takes the maximum value
Ford SUV "Mustang" officially went offline, safe and comfortable









