JavaScript

超轻量级php框架startmvc

vue-cli随机生成port源码的方法

更新时间:2020-09-10 11:24:01 作者:startmvc
vue-cli随机生成port源码的方法constportfinder=require('portfinder');constport=awaitportfinder.getPortPromise()

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);//随机颜色
 }
})

总结

以上所述是小编给大家介绍的vue-cli随机生成port源码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持! 如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

vue cli随机生成 vue port