uniapp常见问题
# Invalid Host header
编辑mainfest.json
文件, 添加如下配置
{
"h5": {
"devServer": {
"disableHostCheck": true
}
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# 蓝牙操作
# 分段写入
const writeValue = '要写入的数据'
var buffercc = new ArrayBuffer(writeValue.length);
var uint8Buf = new Uint8Array(buffercc);
for (var i = 0; i < writeValue.length; i++) {
uint8Buf[i] = writeValue.charCodeAt(i);
}
/**
* 分割数组
* @param {Object} datas
* @param {Number} size 每个数组的大小
*/
function split_array(datas, size) {
var result = {};
var j = 0;
for (var i = 0; i < datas.length; i += size) {
result[j] = datas.slice(i, i + size);
j++;
}
return result;
}
var sendloop = split_array(uint8Buf, 20);
// 分包发送数据
function realWriteData(sendloop, i) {
var data = sendloop[i];
if (typeof data == "undefined") {
console.log("操作成功");
return;
}
console.log("第【" + i + "】次写数据" + data);
var buffer = new ArrayBuffer(data.length);
var dataView = new DataView(buffer);
for (var j = 0; j < data.length; j++) {
dataView.setUint8(j, data[j]);
}
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId: writeId,
value: buffer,
success(res) {
realWriteData(sendloop, i + 1);
},
fail(err) {
uni.hideLoading();
},
});
}
realWriteData(sendloop, 0);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 小程序中样式无法穿透问题
在要穿透样式的页面加入以下代码
<script>
export default {
// 解除子组件样式隔离
options: {
styleIsolation: 'shared'
},
}
<script>
<style scoped>
::v-deep .container {}
</style>
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
上次更新: 2025/07/16, 16:08:11