时间:2021-06-21 08:43:08 | 栏目:vue | 点击:次
vue-cli随机生成port源码的方法
const portfinder = require('portfinder');
const port = await portfinder.getPortPromise();
两行代码
端口搜索范围
默认情况下,portfinder将开始搜索8000并扫描,直到达到最大端口号(65535)
源码的路径是在node_modules/@vue/cli-service/lib/commands/serve.js
知识点扩展:
vue 随机色生成
把标题的颜色设置成随机色
<h4 v-rainbow>标题随机色</h4>
在script写局部自定义指令(如果想要写全局的需要在main.js里面书写)
局部
directives:{
'rainbow':{
bind(el,binding,vnode){
el.style.color = '#' + Math.random().toString(16).slice(2,8);//随机颜色
}
},
}
全局(main.js)
Vue.directive("rainbow",{
bind(el,bind,vnode){
el.style.color = '#' + Math.random().toString(16).slice(2,8);//随机颜色
}
})
总结