gpt4 book ai didi

javascript - 视觉 : Trouble retrieving cookie and passing into request

转载 作者:搜寻专家 更新时间:2023-10-30 22:17:06 25 4
gpt4 key购买 nike

  methods: {
getCookie (name) { /// Retrieve cookie function
match = document.cookie.match(new RegExp(name + '=([^;]+)'));
if (match) return match[1];
return
},
handleLoginFormSubmit () {
const postData = {
username: this.login.username,
password: this.login.password
}
const servicegroupid = getCookie("servicegroupid") ///Call cookie function assign to var
const authUser = {}

this.$http.post(loginUrl + "/" + servicegroupid, postData, {emulateJSON: true}) /// Pass variable into request
.then(response => {
if (response.status === 200) {
console.log('session', response)
authUser.auth = response.data.auth
authUser.sgid = response.data.sgid
authUser.user = this.login.username
window.localStorage.setItem('authUser', JSON.stringify(authUser))
this.$store.dispatch('setUserObject', authUser)
this.$router.push({name: 'dashboard'})
}
})
}
}

尝试检索 cookie,将其分配给变量,然后将其传递到请求中。获取大量未定义。

Vuex、资源和路由器都工作正常。

获取错误:

getCookie is not defined

如果我尝试将函数从方法 block 中拉出,我会得到

match is not defined

非常感谢任何帮助。

最佳答案

改变

const servicegroupid = getCookie("servicegroupid") 

const servicegroupid = this.getCookie("servicegroupid")

这是您的组件的一个方法。

关于javascript - 视觉 : Trouble retrieving cookie and passing into request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42797346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com