Vue之华丽呼哨可还行系列

最简单的单行评级组件

let rate=3;
"★★★★★☆☆☆☆☆".slice(5 - rate, 10 - rate);

定义一个变量 rate 是 1 到 5 的值,然后执行上面代码

效果如下:

image

JS 错误处理的方式的正确姿势(直接定位错误原因)

try {
    // something
} catch (e) {
    window.location.href =
        "http://stackoverflow.com/search?q=[js]+" + e.message;
}

如何快速知道所有元素边框

[].forEach.call($$("*"),function(a){
    a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)
})

换成另一种比较常见的写法就是:

Array.prototype.forEach.call(
	document.querySelectorAll("*"),
	dom => dom.style.outline =`1px solid #${parseInt(Math.random() * Math.pow(2,24)).toString(16)}`
)
浏览器效果如下:

image
image

原文地址:https://www.cnblogs.com/mjtabu/p/15347943.html