Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Listen for device shake events.
my.watchShake({ success() { console.log('Device was shaken!'); } });
Page({ onLoad() { this.enableShakeRefresh(); }, enableShakeRefresh() { my.watchShake({ success: () => { my.vibrate(); this.refreshData(); // Re-enable shake detection this.enableShakeRefresh(); } }); }, refreshData() { my.showLoading({ content: 'Refreshing...' }); my.request({ url: 'https://api.example.com/data', success: (res) => { this.setData({ items: res.data }); my.hideLoading(); } }); } });
Page({ data: { options: ['Option A', 'Option B', 'Option C', 'Option D'], selected: null }, onLoad() { this.startShakeDetection(); }, startShakeDetection() { my.watchShake({ success: () => { my.vibrate(); this.selectRandom(); this.startShakeDetection(); } }); }, selectRandom() { const { options } = this.data; const randomIndex = Math.floor(Math.random() * options.length); this.setData({ selected: options[randomIndex] }); } });
my.watchShake