onShow生命周期功能未触发QuickApp?



我有一个快速的应用程序,我写它包含一个快速的应用程序页面,通过路由器只引用一个自定义元素。push API,该页面的onShow生命周期函数不能被触发。

<import name="listone" src="./aa.ux"></import>
<template>
<!-- The template can contain only one root node. -->
<listone></listone>
</template>
<script>
import prompt from '@system.prompt'
export default {
private: {
},
onInit: function() {
},
onShow() {
console.log('Enter a string whatever you like.');
prompt.showToast({
message: 'Enter a string whatever you like.'
})
}, // This function cannot be triggered.
}
</script>
<style>
.demo-page {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 40px;
text-align: center;
}
</style>

和我的aa。用户体验文件

<template>
<div class="container">
<text> Enter some words.</text>
<text>Enter some words.</text>
<text>Enter some words.</text>
<text>Enter some words.</text>
</div>
</template>
<style>
.container {
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #00fa9a;
}
</style>
<script>
module.exports = {
data: {
},
onInit() {
},
}
</script>

我怎么能得到onShow函数触发在这种情况下?

我已经找到了问题的根源,如果页面的根节点是自定义元素,快速应用加载器不会触发onShow生命周期函数。但是,可以为子元素触发该函数。因此,解决这个问题的方法是添加一个额外的div元素,如:

<template>
<!-- The template can contain only one root node. -->
<div>
<listone></listone>
</div>
</template>

最新更新