如何为 Vue JS 2 应用程序创建唯一标识符
我想知道是否有一种好方法为 Vue JS 2 应用程序提供 UUID。
我目前正在开发一个 Laravel API,供 Android/IOS 设备使用,这些设备通过 install_id 来标识自己。由于它仅在新应用程序安装时发生变化,因此这似乎是实现此目的的最佳方法。
现在我必须开发Vue JS应用程序,但是当然,没有这样的事情。我找到了这个包,但不幸的是,它只支持 Vue JS 3: https://github.com/ VitorLuizC/vue-uuid
基本上,我需要的是 uuid
每个应用程序实例 在页面刷新甚至硬刷新时持续存在(不确定是否可能)在all)意味着从 localStorage 中清除应用程序数据。
到目前为止,我只能想象使用 this 创建随机 uuid
并将其存储在 localStorage 上,然后在应用程序安装时检查 localStorage 上是否存在此 uuid
,如果不存在,则存储它,否则继续。
import { v4 as uuidv4 } from 'uuid'
...
new Vue({
router,
mounted () {
if (!localStorage.getItem('installation_id')) {
localStorage.setItem('installation_id', uuidv4())
}
}
render: h => h(App)
}).$mount('#app')
我将不胜感激任何帮助找到实现这一目标的正确途径。
I'm wondering if there is a nice way to have a UUID for a Vue JS 2 App.
I'm currently developing a Laravel API that is consumed by Android/IOS devices that identifies themselves by using the installation_id. Since it only changes on new app installation, it seems like the best approach for this purpose.
Now I have to develop the Vue JS app, but of course, there is no such thing. I've found this package but unfortunately, it only supports Vue JS 3: https://github.com/VitorLuizC/vue-uuid
Basically, what I need is to have uuid
per app instance which persist on page refresh and even of hard refresh (not sure if possible at all) meaning clearing the app data from localStorage.
So far, I can only imagine creating a random uuid
using this and storing it on localStorage, then on app mount check if this uuid
exists on localStorage and if not, store it, otherwise just continue on.
import { v4 as uuidv4 } from 'uuid'
...
new Vue({
router,
mounted () {
if (!localStorage.getItem('installation_id')) {
localStorage.setItem('installation_id', uuidv4())
}
}
render: h => h(App)
}).$mount('#app')
I will appreciate any help to get the right path to achieve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论