在调用接口页面的<script>部分增加如下配置。
import resident from '@system.resident'
或
const resident= require('system.resident') 描述
启动后台运行。目前为空实现。
OBJECT参数
参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
desc | string | 否 | 目前设置的值不会体现在通知栏。 |
示例代码
resident.start({
desc: ' '
}) <template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<div class="item-container">
<input type="button" class="btn" onclick="test_residentstart" value="resident start" />
</div>
<div class="item-container">
<input type="button" class="btn" onclick="test_residentstop" value="resident stop" />
</div>
</div>
</template>
<style>
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.item-container {
margin-top: 50px;
margin-right: 30px;
margin-left: 30px;
flex-direction: column;
}
.btn {
background-color: #0faeff;
color: #ffffff;
width:400px;
height: 100px;
font-size: 50px;
border-radius:15px;
}
.content {
border: 2px ;
border-radius: 10px;
text-align: center;
}
</style>
<script>
import resident from '@system.resident'
import prompt from '@system.prompt';
module.exports = {
data: {
info:''
},
onInit() {
this.$page.setTitleBar({
text: 'resident',
textColor: '#ffffff',
backgroundColor: '#007DFF',
backgroundOpacity: 0.5,
menu: true
});
},
test_residentstart() {
console.log("start running in the background");
resident.start({
desc: ' 备份进度 30%'
})
prompt.showToast({
message: 'start running in the background',
duration: 2000,
gravity: 'bottom'
});
},
test_residentstop() {
resident.stop()
console.log("stop running in the background");
prompt.showToast({
message: 'stop running in the background',
duration: 2000,
gravity: 'bottom'
});
}
}
</script> 效果图如下:
