localhost 和 127.0.0.1 跨域session 你考虑了么?

博客探讨了在开发过程中,localhost与127.0.0.1不同URL可能导致的跨域Session问题,强调了保持URL一致性的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
  <div id="xxxFullScreen">
    <el-row :gutter="20">
      <el-col :span="2">
        <div class="grid-content bg-purple">
          <p></p>
        </div>
      </el-col>
      <el-col :span="19">
        <div class="grid-content bg-purple">
          <el-container>
            <el-header style="background: darkgrey;">
              <H1 style="margin-left: 380px">欢迎来到腾讯会议</H1>
            </el-header>
            <el-container>
              <el-aside width="200px">
                <el-button type="danger" style="    margin-top: 30px;margin-bottom: 20px;">退出会议</el-button>
                <el-table :data="tableData" style="width: 100%">
                  <el-table-column prop="username" label="学生姓名" width="180"></el-table-column>
                </el-table>
              </el-aside>
              <el-container>
                <h1>会议名称 : {{comment1.meetingName}}</h1>

                <el-main>
                  <el-table :data="comment1" height="400" border style="width: 100%">
                    <el-table-column prop="name" label="姓名" width="180"></el-table-column>
                    <el-table-column prop="comment" label="内容" width="180"></el-table-column>
                  </el-table>
                  <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="textarea"></el-input>
                  <el-button type="primary" @click="sendComment">发送</el-button>
                </el-main>
              </el-container>
            </el-container>
          </el-container>
        </div>
      </el-col>
      <el-col :span="1">
        <div class="grid-content bg-purple">
          <p></p>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [],
      textarea: "",
      // comment: [],
      comment1: []
    };
  },
  methods: {
    sendComment: function() {
      this.axios({
        method: "POST",
        url: "http://localhost:8081/meeting/comment", // 成功
        data: JSON.stringify({
          comment: this.textarea
        }),
        withCredentials: true,
        headers: {
          "Content-Type": "application/json"
        }
      }).then(response => {
        this.comment1 = response.data;
        this.textarea = "";
      });
    },
    shUsername: function() {
      this.axios({
        method: "POST",
        url: "http://localhost:8081/meing/data",//之前写成http://127.0.0.1:8081/meing/data   不成功
        data: JSON.stringify({
          comment: this.textarea
        }),
        withCredentials: true,
        headers: {
          "Content-Type": "application/json"
        }
      }).then(response => {
        console.log("hahha");
        this.tableData = response.data;
        console.log(response.data);
      });
    }
  },
  created() {
    this.shUsername();
  }
};
</script>

坑就在于这两个url 使用 localhost 和 127.0.0.1 要一致
时间有限 简要记录一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值