proxy:"https://www.t2c.site"
(坑所在,待會詳講!)<template> <b-img src="/user/checkCode?k=0.1" onclick="this.src='/checkCode?k='+Math.random()"></b-img> //account、password部分是兩個input按鈕、省略 <button type="button" id="login-button" @click="submit">Login</button> </template> <script> export default { data() { return{ account:'', password:'', checkCode:'' } }, methods:{ submit(){ this.axios.post('/user/login', { account: this.account, password: this.password, checkCode: this.checkCode },{ withCredentials:true }) .then( (response) =>{ console.log(response.data); }) .catch( (error)=> { console.log(error); }); } } } </script>
前端main.js:axios.defaults.withCredentials=true; 後端已設置:Access-Control-Allow-Credentials: true
就是補全域名!!!前端
<b-img src="https://www.t2c.site/user/checkCode?k=0.1" onclick="this.src='https://www.t2c.site/checkCode?k='+Math.random()"></b-img> this.axios.post('https://www.t2c.site/user/login'
三個請求地址必須補全,缺一不可。vue
www.t2c.site
;這規定了這個cookie只有在請求域名爲www.t2c.site時纔會被攜帶發送到後端