| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- Page({
- onShareAppMessage() {
- return {
- title: '监听罗盘数据',
- path: 'page/API/pages/on-compass-change/on-compass-change'
- }
- },
- data: {
- enabled: true,
- direction: 0
- },
- onReady() {
- const that = this
- wx.onCompassChange(function (res) {
- that.setData({
- direction: parseInt(res.direction, 10)
- })
- })
- },
- startCompass() {
- if (this.data.enabled) {
- return
- }
- const that = this
- wx.startCompass({
- success() {
- that.setData({
- enabled: true
- })
- }
- })
- },
- stopCompass() {
- if (!this.data.enabled) {
- return
- }
- const that = this
- wx.stopCompass({
- success() {
- that.setData({
- enabled: false
- })
- }
- })
- }
- })
|