目录

Log Recording

API Declaration

No declaration is required.

Module Import

No declaration is required.

Application Scope

Item

Description

Applicable devices

Mobile phones, tablets, Vision products, and telematics devices

Applicable regions

Global

Definition

API

Description

console.debug/log/info/warn/error(message)

Records a text in Huawei Quick App IDE.

[h2]console.debug/log/info/warn/error(message)

Description

Records a text in Huawei Quick App IDE.

Parameters

Parameter

Type

Mandatory

Description

message

string

Yes

Text to be recorded, which can be formatted text and complies with the rules same as those of the browser console.

Sample code

for (var i=0; i<5; i++) {
 console.log("Hello, %s. You've called me %d times.", "Bob", i+1);
 }
 console.log("I want to print a number: %d", 123456);

Demo

<template>
  <div class="container">
    <div class="page-title-wrap">
      <text class="page-title">{{componentName}}</text>
    </div>
    <input type="button" class="btn" value="getPackageInfo" onclick="getPackageInfo" />
    <text class="label" id="text">{{info}}</text>
    <text class="label">{{packageInfo}}</text>
  </div>
</template>

<style>
.container{
  flex: 1;
  flex-direction: column;
}

.page-title-wrap {
  padding-top: 50px;
  padding-bottom: 80px;
  justify-content: center;
}
.page-title{
  padding-top: 30px;
  padding-bottom: 30px;
  padding-left: 40px;
  padding-right: 40px;
  border-color: #bbbbbb;
  color: #bbbbbb;
  border-bottom-width: 2px;
}

.btn {
  height: 80px;
  text-align: center;
  border-radius: 5px;
  margin-right: 60px;
  margin-left: 60px;
  margin-bottom: 50px;
  color: #ffffff;
  font-size: 30px;
  background-color: #0faeff;
}  

  a {
    margin-left: 75px;
    width: 600px;
    padding-top: 50px;
    padding-bottom: 50px;
    margin-bottom: 100px;
    background-color: #ffffff;
    text-decoration: underline;
    text-align: center;
  }
</style>

<script>
  import app from '@system.app'
  export default {
    data: {
      componentName: 'LogRecording',
      info: '',
      packageInfo: ''
    },
    onInit() {
      this.$page.setTitleBar({ text: 'LogRecording' })
      this.info = JSON.stringify(app.getInfo())
      console.log(JSON.stringify(app.getInfo()))
    },
    getPackageInfo() {
      app.getPackageInfo({
        packageName: 'com.tencent.mm',
        success: (data) => {
          this.packageInfo = JSON.stringify(data)
          console.info('getPackageInfo success', JSON.stringify(data))
        },
        fail: (errormsg, errorcode) => {
          this.packageInfo = 'get fail --- ' + errorcode + ':' + errormsg
          console.info('get fail --- ' + errorcode + ':' + errormsg)
        },
        complete: () => {
          console.info('get complete.')
        }
      })
    }
  }
</script>

The following figure shows the final effect.