vue 本地开发时使用localhost与ip访问

修改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=/' } } } } }

  

转载于:https://www.cnblogs.com/alantao/p/9698235.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值