[英]How to store referrer url in NUXT js?
I want to store the referrer url in local storage.我想将推荐人 url 存储在本地存储中。 My project is based on nuxt js.
我的项目基于 nuxt js。 This is what I have so far.
这就是我到目前为止所拥有的。 I tried localStorage.setItem but it is not seeming to work.
我尝试了 localStorage.setItem 但它似乎不起作用。 How can I solve this?
我该如何解决这个问题?
if (this.$route.query.ref) {
localStorage.setItem("referrer", '$route.query.referrer');
this.$axios
.$post("/affiliates/createClick", {
referral_code: this.$route.query.ref
})
.then(response => {
this.click_id = response.data.id;
console.log(this.click_id);
// this.referral_code = this.$route.query.ref;
const options = {
path: "/",
maxAge: 60 * 60 * 24 * 45
};
const cookieList = [
{
name: "affiliate_id",
value: this.$route.query.ref,
opts: options
},
{ name: "click_id", value: this.click_id, opts: options }
];
this.$cookies.setAll(cookieList);
});
}
else if (this.$route.query.referrer) {
// sessionStorage.setItem("referrer", '$route.query.referrer');
console.log(this.$route.query.referrer);
// this.referral_code = this.$route.query.ref;
const options = {
path: "/",
maxAge: 60 * 60 * 24 * 45
};
const cookieList = [
{
name: "referrer",
value: this.$route.query.referrer,
opts: options
}
];
this.$cookies.setAll(cookieList);
}
},
This issue here is likely that at some point you set an string in local storage that is not JSON-parseable.这里的这个问题很可能是因为您在本地存储中设置了一个不可解析 JSON 的字符串。 You Can try this
你可以试试这个
localStorage.setItem('referrer', JSON.stringify('$route.query.referrer'))
localStorage.setItem('referrer', JSON.stringify('$route.query.referrer'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.