你好我需要一个小程序源码它只需要有骰子的功能
您好,以下是一个简单的骰子小程序源码,供您参考:
//index.js
Page({
data: {
result: 0
},
rollDice: function () {
let result = Math.floor(Math.random() * 6) + 1;
this.setData({
result: result
});
}
})
<!--index.wxml-->
<view class="container">
<view class="dice" bindtap="rollDice">
<view class="result">{{result}}</view>
</view>
</view>
/*index.wxss*/
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.dice {
display: flex;
justify-content: center;
align-items: center;
width: 100px;
height: 100px;
border: 1px solid black;
border-radius: 50%;
font-size: 36px;
}
.result {
margin-top: 10px;
font-size: 24px;
}
这个小程序只有一个页面,包含一个骰子元素和一个结果显示元素。当用户点击骰子时,程序会随机生成一个1到6的数字,并将结果显示在页面上。
希望能对您有所帮助!
原文地址: https://www.cveoy.top/t/topic/b5yA 著作权归作者所有。请勿转载和采集!