Skip to content

Commit bb122be

Browse files
committed
feat: add generateSafeId funtion.
1 parent 803eded commit bb122be

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/mixins/safeId.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
export default{
2-
id: {
3-
type: String,
4-
default: null
5-
},
62
computed: {
73
safeId () {
8-
if(this.id)
9-
return this.id
10-
return Math.random().toString(36).replace('0.', '') + (new Date()).getTime().toString(36)
4+
if(this.id || this.$attrs.id)
5+
return this.id || this.$attrs.id
6+
return generateSafeId()
117
}
128
}
139
}
10+
11+
function generateSafeId () {
12+
const key = Math.random().toString(36).replace('0.', '') +
13+
(new Date()).getTime().toString(36)
14+
return '__safe_id__' + key
15+
}

0 commit comments

Comments
 (0)