您现在的位置是:首页 > 短信大全

vue前端获取本地IP地址

作者:纳雷武时间:2024-04-25 16:48:59分类:短信大全

简介  文章浏览阅读806次,点赞9次,收藏7次。在index.js文件中添加以下配置。_vue获取当前电脑ip地址

点击全文阅读

新建js文件

getIpAddress.js

//获取本机的IP地址function getNetworkIp() {    let ip = 'localhost';    try {        const network = Os.networkInterfaces();//获取本机的网路        for (const iter in network) {            const faces = network[iter];            for (const interface of faces) {                if (interface.family === 'IPv4' && interface.address !== '127.0.0.1' && !interface.internal) {                    ip = interface.address;                    return ip;                }            }        }    } catch (e) {    }    return ip;}module.exports = getNetworkIp;

在index.js文件中添加以下配置

dev: {    // Paths    assetsSubDirectory: 'static',    assetsPublicPath: '/',    proxyTable: {},    // Various Dev Server settings    host: getNetworkIp(), // can be overwritten by process.env.HOST    useLocalIp: true,//允许使用本地IP地址进行访问    port: 18880, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined    autoOpenBrowser: false,    errorOverlay: true,    notifyOnErrors: true,    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-    /**     * Source Maps     */    // https://webpack.js.org/configuration/devtool/#development    devtool: 'cheap-module-eval-source-map',    // If you have problems debugging vue-files in devtools,    // set this to false - it *may* help    // https://vue-loader.vuejs.org/en/options.html#cachebusting    cacheBusting: true,    cssSourceMap: false  },

点击全文阅读

郑重声明:

本站所有活动均为互联网所得,如有侵权请联系本站删除处理

上一篇:三好学生自荐书

下一篇:返回列表

我来说两句