[英]How to get query from url and send it to Store at nuxt js project
[英]How to store referrer url in NUXT js?
我想將推薦人 url 存儲在本地存儲中。 我的項目基於 nuxt js。 這就是我到目前為止所擁有的。 我嘗試了 localStorage.setItem 但它似乎不起作用。 我該如何解決這個問題?
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);
}
},
這里的這個問題很可能是因為您在本地存儲中設置了一個不可解析 JSON 的字符串。 你可以試試這個
localStorage.setItem('referrer', JSON.stringify('$route.query.referrer'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.