通过 username=ab;domain=.test.com;设置username值为ab,主域名为.test.com的IP可以跨域获取到该值。
主域名不是.test.com的IP则获取不到该值。
<template>
<div class="home">
<input v-model="test" />
<button @click="getCookie">获取</button>
<button @click="setCookie">保存</button>
</div>
</template>
<script>
export default {
name: "HomeView",
data: () => {
return {
test: "",
};
},
methods: {
getCookie() {
this.test = document.cookie;
},
setCookie() {
console.log(this.test);
document.cookie = this.test;
},
}
};
</script>
Nginx配置
这样就能实现同个主域名下不同的IP可以跨域获取彼此的值了!