generateId() {
const s = [];
const hexDigits = '0123456789abcdef';
for (let i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
// bits 12-15 of the time_hi_and_version field to 0010
s[14] = '4';
// bits 6-7 of the clock_seq_hi_and_reserved to 01
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
s[8] = s[13] = s[18] = s[23] = '-';
const uuid = s.join('');
return uuid;
},
主要解决的问题是:
当不经过数据库操作,新增和删除只是前端进行简单的处理,等点击save才进入数据库时,这时候需要考虑随机数的应用了。
新增的时候,进行push操作
this.dataList.push({
name:'',
titile:'',
id:this.generateId()
})
删除的时候
/** 删除数据的方法*/ deleteData(row){ // 你确定要删除这条数据嘛? this.$confirm('Are you sure you want to delete this data?', 'Delete', { cancelButtonText: 'Cancel', confirmButtonText: 'OK', type: 'warning' }).then(() => {
this.dataList = this.dataList.filter(item => (item.id !== row.id));}).catch(() => { }); },