当前位置:网站首页>Wechat applet: click the event to obtain the current device information (basic)

Wechat applet: click the event to obtain the current device information (basic)

2022-06-13 06:08:00 HaanLen

Bind event to get current device information

pages/study/index.wxml

<!--pages/study/index.wxml-->
<text>pages/study/index.wxml</text>
<view>{
   {text}}</view>
<button type="primary" bindtap="getInfo"> Click for information </button>

pages/study/index.ts

// pages/study/index.ts
Page({
    

    /** *  Initial data of the page  */
    data: {
    
        text: ''
    },

    /** *  Life cycle function -- Monitor page loading  */
    onLoad() {
    

    },

    /** *  Life cycle function -- Listening page first rendering completed  */
    onReady() {
    

    },

    /** *  Life cycle function -- Monitor page display  */
    onShow() {
    

    },

    /** *  Life cycle function -- Monitor page hidden  */
    onHide() {
    

    },

    /** *  Life cycle function -- Monitor page uninstall  */
    onUnload() {
    

    },

    /** *  Page related event handler -- Monitor user pull-down action  */
    onPullDownRefresh() {
    

    },

    /** *  Handling function of page pull bottom event  */
    onReachBottom() {
    

    },

    /** *  Users click the upper right corner to share  */
    onShareAppMessage() {
    

    },
    getInfo() {
    
        wx.getSystemInfo({
    
            success: (res) => {
    
                console.log('res', res);
                let str = ` equipment :${
      res?.model},  platform :${
      res?.platform}`
                this.setData({
    
                    text: str
                })
            }
        })

    }
})

Return information

{
    
	SDKVersion: "2.22.1"
	batteryLevel: 0
	benchmarkLevel: 1
	bluetoothEnabled: true
	brand: "devtools"
	cameraAuthorized: true
	deviceOrientation: "portrait"
	devicePixelRatio: 3
	enableDebug: false
	errMsg: "getSystemInfo:ok"
	fontSizeSetting: 16
	language: "zh_CN"
	locationAuthorized: true
	locationEnabled: true
	microphoneAuthorized: true
	mode: "default"
	model: "iPhone 6/7/8 Plus"
	notificationAuthorized: true
	pixelRatio: 3
	platform: "devtools"
	safeArea: {
    top: 20, left: 0, right: 414, bottom: 736, width: 414,}
	screenHeight: 736
	screenWidth: 414
	statusBarHeight: 20
	system: "iOS 10.0.1"
	version: "8.0.5"
	wifiEnabled: true
	windowHeight: 624
	windowWidth: 414
}

 Insert picture description here
 Insert picture description here
 Insert picture description here

Real machine debugging
 Insert picture description here

原网站

版权声明
本文为[HaanLen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130603576039.html