| 12345678910111213141516171819202122232425262728 |
- <template>
- <div>
- <button @click="scanBluetooth">扫描蓝牙设备</button>
- </div>
- </template>
- <script>
- export default {
- methods: {
- async scanBluetooth() {
- if (!navigator.bluetooth) {
- console.log('此浏览器不支持 Web Bluetooth API。:');
- // alert("此浏览器不支持 Web Bluetooth API。");
- return;
- }
- try {
- const device = await navigator.bluetooth.requestDevice({
- filters: [{services: ['battery_service']}]
- });
- console.log('选择的设备:', device);
- } catch (error) {
- console.error('错误:', error);
- }
- }
- }
- }
- </script>
|