|
本帖最后由 jy 于 2018-6-11 12:38 编辑
在华为快应用加载器中,web组件无法触发 titlereceive、pagefinish等事件,快应用官方调试器没有这个问题
下面是代码:- <template>
- <!-- template里只能有一个根节点 -->
- <div class="container">
- <text class="title">
- Hello {{title}}
- </text>
- <input type="button" value="网页" onclick="onWebShow()"></input>
- <web id="web" ontitlereceive="onWebTitChange" onpagefinish="onWebLoaded" src="{{webUrl}}" style="display:{{webShow ? 'flex':'none'}};"></web>
- </div>
- </template>
-
- <style>
- web{position:fixed;left:0;top:0;right:0;bottom:0;display:none;width:100%;height:100%;}
- .container {
- flex-direction: column;
- justify-content: center;
- align-content: center;
- align-items: center;
- }
-
- .title {
- font-size: 100px;
- }
- </style>
-
- <script>
- import prompt from '@system.prompt'
- import shortcut from '@system.shortcut'
- import webview from '@system.webview'
-
- module.exports = {
- data: {
- title: 'World',
- webUrl:'',
- webShow:false
- },
- onWebShow(){
- var url = 'http://www.baidu.com';
- var url1 = 'https://quickapp.cn';
- if(this.webUrl && this.webUrl == url){url = url1}
-
- if(url != this.webUrl){
- this.webShow = true;
- this.webUrl = url;
- }else{
- this.webShow = true;
- }
- return;
- },
- onWebLoaded(){
- prompt.showDialog({
- title: '提示',
- message: "网页加载完成",
- buttons: [
- {
- text: '确定',
- color: '#33dd44'
- }
- ]
- });
- },
- onWebTitChange(tobj){
- prompt.showDialog({
- title: '提示',
- message: tobj.title,
- buttons: [
- {
- text: '确定',
- color: '#33dd44'
- }
- ]
- });
- },
- onInit() {
- this.$page.setTitleBar({
- text: 'menu',
- textColor: '#ffffff',
- backgroundColor: '#007DFF',
- backgroundOpacity: 0.5,
- menu: true
- })
- },
- onMenuPress() {
- var that = this;
- prompt.showContextMenu({
- itemList: ['关闭网页','添加到桌面'],
- success: function (data) {
- if(data.index == 0){
- that.webShow = false;
- }else if(data.index == 1){
- shortcut.install({
- success: function () {
- // 使用应用加载器时,请先在设置中打开应用加载器的桌面快捷方式
- prompt.showToast({
- message: "桌面图标创建成功"
- })
- },
- fail: function (erromsg, errocode) {
- prompt.showToast({message: "创建失败" + errocode + ': ' + erromsg})
- },
- complete: function () {
- console.log('shortcut complete');
- }
- })
- }
- },
- fail: function (data, code) {
- console.log("handling fail, code=" + code);
- },
- cancel: function (data) {
- console.log("handling cancel");
- },
- complete: function () {
- console.log("handling complete");
- },
- })
-
- }
- }
- </script>
复制代码 华为渲染器效果:
http://u2988804.ctcontents.com/drfiles/2988804/294379386/hw.mp4
快应用官方渲染器效果:
http://u2988804.ctcontents.com/d ... 379389/quickapp.mp4
|
|