我正在尝试在JavaScript中创建全局唯一标识符.我不确定所有浏览器上有哪些例程,"随机"和内置随机数生成器的种子等等.
GUID/UUID应至少为32个字符,并应保持在ASCII范围内,以避免传递它们时出现问题.
我有这个vue函数,其中基本上有两种方法.第一个postStatus用于在用户单击保存按钮后保存帖子,另一个getPosts用于从数据库中检索该用户的所有先前帖子.
这是vue.js,其中有一个对控制器的ajax调用(在Laravel 5.3中)
$(document).ready(function () {
var csrf_token = $('meta[name="csrf-token"]').attr('content');
/*Event handling within vue*/
//when we actually submit the form, we want to catch the action
new Vue({
el : '#timeline',
data : {
post : '',
posts : [],
token : csrf_token,
limit : 20,
},
methods : {
postStatus : function (e) {
e.preventDefault();
//console.log('Posted: '+this.post+ '. Token: '+this.token);
var request = $.ajax({
url : '/posts',
method : "POST",
dataType : 'json',
data : …Run Code Online (Sandbox Code Playgroud) 假设我有一个 JS 组件——我使用的是 Vue.JS——其中有一个复选框和相关的标签:
<template>
<input id="field1" type="checkbox">
<label for="field1">
Some label
</label>
</template>
Run Code Online (Sandbox Code Playgroud)
现在,由于我们设计了可重用的组件,我想同时在我的应用程序的多个位置使用它。问题:ID 重复,单击复选框的标签会检查另一个复选框,因为它们共享相同的 ID。
如何解决这个问题呢?
现在我在组件安装时生成一个随机的十六进制 ID 来生成唯一的 ID 值,但感觉太黑了。