uni-app随机数生成器
核心
Math.floor(Math.random() * (this.max - this.min + 1) ) + this.min
代码
<template>
<view>
<input style="border: 1px solid;" type="text" v-model="min" placeholder="请输入最小值"/>
<input style="border: 1px solid;" type="text" v-model="max" placeholder="请输入最大值"/>
<button @click="getRand">点击生成</button>
<input style="border: 1px solid;" type="text" :value="rand" placeholder="结果" disabled="true"/>
</view>
</template>
<script>
export default {
data() {
return {
max:0,
min:0,
rand:0
}
},
onLoad() {
},
methods: {
getRand(){
console.log(this.min)
console.log(this.max)
this.rand = Math.floor(Math.random() * (this.max - this.min + 1) ) + this.min
}
}
}
</script>
<style>
</style>
更多推荐
uni-app随机数生成器
发布评论