【发布时间】:2021-10-15 15:16:36
【问题描述】:
我正在尝试通过被动方式生成密码。我的实例中有一个数组对象,我可以用 v-for 列出这个对象。另外,我可以生成带有passArry 中字符的随机密码。但是当检查复选框时,我需要在数据中发送chars 987654323 @。但是联系不上options.status怎么办?
<div class="form-check" v-for="options in options" :key="options.optionName">
<input type="checkbox" class="form-check-input" v-model="options.status">
export default {
data() {
return {
generate: 5,
result: '',
passArry : [],
options :[
{
optionName : 'Lowercase',
status : true,
chars : 'abcdefghijklmnopqrstuvwxyz',
},
{
optionName: 'Uppercase',
status: false,
chars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
},
{
optionName: 'Numbers',
status: true,
chars: '1234567890',
},
{
optionName: 'Symbols',
status: false,
chars: '~!@#$%^&*()_-+={[}]|:;<,>.?/'
},
]
}
},
watch:{
generate(){
this.result.length > 0 ? this.result = '' : this.result
let charLength = this.passArry.length;
for(let i = 0; i < this.generate; i++){
this.result += this.passArry[Math.floor(Math.random() * charLength )]
}
},
【问题讨论】: