node+axios+cookie填坑
昨天用node写后端接口,前端axios请求,遇到好多坑,总结一下: 1.axios传参异常 this.axios.post(this.$route.meta.api.login, { account: this.form.account, password: this.form.password }) 一开始使用这届对象传参的方式,发现后台接受到的参数为空对象,上网查了一下,说是需要添加 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' 于是在全局中添加了上面代码,发现还是没用。最终通过如下方式解决: let formData = new URLSearchParams() formData.append('account', this.form.account) formData.append('password', this.form.password) this.axios.post(this.$route.meta.api.login, formData) 2.cookie无法存储中文 我用cookie保存用户信息,代码如下: req.cookies.set('userInfo', JSON.stringify({ username