修改config文件夹下面的index.js配置,将localhost改为0.0.0.0就可以了。用ip,127.0.0.1,localhost均行

host: '0.0.0.0', // can be overwritten by process.env.HOST

问题: 使用本地ip时访问发现登陆不上,使用localhost反而可以,后查明是cookit存入时存入是domain限制了,用内网ip如192.168.88.34:8080存不了cookei

// 创建  获取  删除cookie
export default {
install (Vue) {
Vue.prototype._COOKIE = {
// 创建cookie
setCookie (name, value, times) {
times = times || 36500
var exp = new Date()
exp.setTime(exp.getTime() + times * 24 * 60 * 60 * 1000)
let domain = '.' + location.host.split('.')[1] + '.' + location.host.split('.')[2]
if (location.host.split('.')[2]) {
document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString() + ';domain=' + domain + ';path=/'
      // 不加domain使用内网ip才可能存上
// document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString() + ';path=/'
} else {
document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString() + ';path=/'
}
},
// 获取cookie
getCookie (name) {
let arrd = null
let reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
if (document.cookie.match(reg)) {
arrd = document.cookie.match(reg)
return unescape(arrd[2])
} else {
return null
}
},
// 删除cookie
removeCookie (name) {
let domain = '.' + location.host.split('.')[1] + '.' + location.host.split('.')[2]
if (location.host.split('.')[2]) {
document.cookie = name + '="";expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=' + domain + ';path=/'
} else {
document.cookie = name + '="";expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/'
// document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString() + ';path=/'
}
}
}
}
}

  

vue 本地开发时使用localhost与ip访问的更多相关文章

  1. vue项目开发时怎么解决跨域

    vue项目中,前端与后台进行数据请求或者提交的时候,如果后台没有设置跨域,前端本地调试代码的时候就会报“No 'Access-Control-Allow-Origin' header is prese ...

  2. 本地测试时修改localhost为自己网站的域名的方法(转载)

    做网站的,在本地测试时,所用的地址基本上都是localhost 或者直接用IP地址:127.0.0.1 如果仅仅是用来测试网站内部的程序代码之类的当然没问题,但是如果我们还要测试网站上添加的广告或者统 ...

  3. 【django】本地开发media用户上传文件访问路径找不到

    当我们在本地开发的时候,会碰到static可以访问,但是用户上传的文件设置在media下不可访问怎么办?settings配置: 接着在你的urls文件添加: from . import setting ...

  4. vue项目启动时将localhost替换成指定ip地址

    1.node启动vue项目时地址一般都是http://localhost:8080 2.config->index.js 中的host:‘localhost’换成host:‘你的本机ip’就可以 ...

  5. 本地开发时同时启动多个tomcat服务器

    1.环境变量中不要设置CATALINA_HOME: 2.分别修改安装目录下的conf子目录中的server.xml文件: a.修改http访问端口(默认为 8080端口),将8080修改为tomcat ...

  6. vue项目不能同时被localhost和ip地址同时访问的方法

    方法1.将index.js中的host的值改为‘0.0.0.0’ 方法2.修改package.json中script下dev的值,在后面加入--host 0.0.0.0 也可以解决

  7. vue-cli启动本地服务,局域网下通过ip访问不到的原因

    1.问题描述: 新开发了一个vue-cli项目,想通过手机查看效果,发现访问不到,ip地址和端口号都没错但是手机访问不到,在本机电脑浏览器输入ip端口号一样访问不到,只能通过localhost:808 ...

  8. 用vue构建项目同一局域网下通过ip访问

    在webpack配置文件下改为 host:'0.0.0.0' 改为后启动跳转不到登录页面 需手动修改浏览器上的0.0.0.0:8080为自己ip加上:8080 就可以在别的电脑上进行访问了 举一反三: ...

  9. vue项目配置同一局域网可使用ip访问

    1.检查 package.json文件,scripts.dev设置 host改成 "0.0.0.0" 2.config文件中找到 index.js 文件的host改成 " ...

随机推荐

  1. python测试开发django-48.xadmin上传图片django-stdimage

    前言 django通过自带的ImageField可以实现图片上传,如果想在列表页面也显示图片缩略图的话,可以用django-stdimage插件来实现 django-stdimage django-s ...

  2. C#模拟HTTP请求Post JSON

    前言 因为接口是http的,我们站点是https的,不能https直接ajax请求http,所以需要在SharePoint中开发一个模拟请求Ajax的Service,分享一下. var httpWeb ...

  3. cocos2d-x项目创建和打包

    1.创建C++的cocos2d-x项目:cocos new test_cpp02 -p com.benmutou.helloWorld -l cpp -d projects C++未编译目录: C++ ...

  4. exited abnormally with signal 11: Segmentation fault 的相关处理

    前一阵子遇到一个问题,程序打包后,在某个界面总是崩溃,device log只打印了exited abnormally with signal 11: Segmentation fault 网上找了下相 ...

  5. 连接mysql 出现:java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.

    数据测试的时候出现: 网上查资料说的是mysql5.x 版本和 8.x版本的区别: 5.7版本是:default_authentication_plugin=mysql_native_password ...

  6. 用户人品预测大赛--就是gan队--竞赛分享

     用户人品预测大赛--就是gan队--竞赛分享  DataCastle运营 发表于 2016-3-24 14:14:05      1194  1  0 答辩PPT

  7. OpenGL核心技术之HDR

    笔者介绍:姜雪伟.IT公司技术合伙人,IT高级讲师,CSDN社区专家.特邀编辑,畅销书作者.国家专利发明人;已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D ...

  8. react 生命周期函数

    (1)初始化阶段:getDefaultProps:获取实例的默认属性static propTypes 设置属性的类型componentWillMount:组件即将首次被装载.渲染到页面上render: ...

  9. 一些Vim使用的小技巧

    1. 全局替换(1) v + G + $ 选定全部,然后输入 :s/原始字符串/目标字符串/(2) :%s/原始字符串/目标字符串/ 2. 清除页面中所有行尾的空白符::%s/s+$// 3. 清除所 ...

  10. GitHub下载安装以及开源项目

    Git for Windows安装与使用 http://cioworld.org/freedom/content/git-windows 下载Git-1.8.3-preview20130601.exe ...