欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue前端獲取本地IP地址代碼實(shí)例

 更新時(shí)間:2024年05月11日 08:55:11   作者:一百減一是零  
再做前端頁(yè)面的時(shí)候,想獲取本地的ip地址,可能是為了和服務(wù)器通信,可能是為了展示,無(wú)論哪種,下面給大家總結(jié)下方法,這篇文章主要給大家介紹了關(guān)于vue前端獲取本地IP地址的相關(guān)資料,需要的朋友可以參考下

新建js文件

getIpAddress.js

//獲取本機(jī)的IP地址
function getNetworkIp() {
    let ip = 'localhost';
    try {
        const network = Os.networkInterfaces();//獲取本機(jī)的網(wǎng)路
        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地址進(jìn)行訪問(wèn)
    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
  },

總結(jié) 

到此這篇關(guān)于vue前端獲取本地IP地址的文章就介紹到這了,更多相關(guān)vue獲取本地IP地址內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論